Update IntegerFormatter.java for negative squelch value (#2187)

Two issues:
(1)documentation for change.getText() says it can be an empty string but never null. 
(2)Need to allow for typing a minus sign before validating min/max.
This commit is contained in:
Randy
2025-03-14 01:52:49 -06:00
committed by GitHub
parent 5b0a1401a1
commit b360950b80

View File

@@ -85,7 +85,7 @@ public class IntegerFormatter extends TextFormatter<Integer>
public Change apply(Change change)
{
//Only validate if the user added text to the control. Otherwise, allow it to go through
if(change.getText() != null)
if(!change.getText().equals(""))
{
String updatedText = change.getControlNewText();
@@ -93,6 +93,12 @@ public class IntegerFormatter extends TextFormatter<Integer>
{
return change;
}
// don't validate yet if input is only a minus sign
if(updatedText.equals("-"))
{
return change;
}
if(!updatedText.matches(DECIMAL_REGEX) || !isValid(updatedText))
{