For a particular project I'm working on the specs say that as a user types a value into a particular cell in a table, I must validate that each character is valid and that they are typing a valid code.
Example: Say valid codes are "01", "02", "10", 11", "20", ... we actually have a large number of codes and not all are numeric.
I have the part about validating as they type, if they type a 0 ... no problem so far so they type as the next character a 3 ... well there's no 03 code in the list so I make the "ding" sound and I don't even allow the 3 to show in the field. they would still see the 0 and the cursor waiting for the next char. and if they then typed 1 ... thats ok because 01 is a valid code. And in this example there are no codes larger than 2 digits so if they tryied to type any more i just make the "ding" and don't add the character.
The checking as they type works great they cannot enter a bad code... what I didn't think about is what if they just type a 1 and then exit the field. It wasn't an error because the char 1 was a valid begining to the code "11" but wasn't the complete code.
What I need to do is a second check when they're done editing the field to see if the code currently there is valid. and if it is not, do not leave the edit portion of the field and stay positioned to the last character and make the "ding" sound just as if they had typed something invalid.
For anyone's curriosity here is the TextField class that I create that columns cell editor from