When deferUpdates is true, you only ‘see’ the text inserted into a field when it has been competed, that is the control loses focus or enter is pressed.
This is very useful because I only validate complete values; infact i bound the control.porps.style.backgroundColor to the text property with a transformation that validates the input and returns green for correct and red for incorrect values:
if int(value)<100: return "#00FF00" else: return "#FF0000"
So far so good.
Now, when the user enters a value that proves to be wrong and makes the background turn red, she starts correcting it, changing the value.
During this editing the background stays red and this is suboptimal because it referes to the previous value. Instead, I would like that the background turned withe again like for not-yet-completed input.
The easiest way to do it is to compare the actual value (that is the not yet committed value) of the TextField with the committed one (that is the text property); if they differ, make the background white (in the background binding, of course; maybe an explicit refresh has to be called to make it work, but these are just details).
Is there a way to access this information?
If not, is there any alternative?
I tried to revert the background color to white on the KeyPress event of the TextField:
self.props.style.backgroundColor = "#FFFFFF"
- Reverting to white works
- Validating (on enter or loosing focus) still works
Unfortunately this introduces another unwanted behavior.
Pressing an additional enter causes a validated (red or green) control to turn white again.
That is because pressing enter triggers the KeyPress event that turns the background white.
Since the binding is intelligent and sees no change in the content, it doesn’t trigger the backgroundColor update anymore because it get refreshed only when there is an actual change in the text property.
This way a validated (red or green) TextField turns white if a second enter is pressed.
If only I could access the actual text property I would have enough infromation to get it right.