PDA

View Full Version : Beta3: TextField not updating it's underlying value.



IgyBoy
19 Feb 2012, 6:48 AM
I know there is similar bug reported for NumberField/SpinnerField, but it seems there is a bug on TextField and on all widgets inherited from CellComponent.

To reproduce it, simply add one TextField widget on Dialog and add declare it as follows:

password = new PasswordField();
password.addValidator(new EmptyValidator<String>());
password.addKeyPressHandler(new KeyPressHandler() {

@Override
public void onKeyPress(KeyPressEvent event) {
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER)
{
if (!password.isValid()) {
//do something if field is not valid....
}
else{
//do something if field is valid
}


} }
}
});

p.add(new FieldLabel(password,"Password"),new VerticalLayoutData(1,-1));



Now,type something in the field and press "enter" key. Now,f you step through source, you'll see that getValue method in CellComponent.class is returning a NULL for a field value.After the field looses the focus,and then gets it again the correct value is returned.

Colin Alworth
20 Feb 2012, 5:15 PM
Through the support added for Cells, so all fields in GXT can be added cheaply directly to Grid or other Cell widgets, the ability to get the value on the fly has been modified - getValue() returns the value after the Cell has finished.

Instead, if you want the instantaneous value while editing is still occurring, try getCurrentValue, available on any ValueBaseField subclass, including TextField. It will read the contents of the dom, avoiding the cell entirely, and parse the value and return it to you.

Subclasses and their Cell instances need to make sure to support this, by exposing a correct input element (ValueBaseField.getInputEl or ValueBaseFieldCell.getInputElement), the currently displayed value (.ValueBaseField.getText), or directly through ValueBaseField.getValueOrThrow or ValueBaseField.getCurrentValue.

IgyBoy
20 Feb 2012, 10:35 PM
Hi Colin,
thank you for your reply.

The problem is that I'm not the one calling the getValue method...instead, the validators are doing it, like in the example I posted above.
I added simple EmptyValidator to PasswordField object and when "enter" key is pressed I check if it is valid, by calling the isValid() method.
The underlying ValueBasedFieldCell component than tries to getValue, but fails, since the "value" in underyling CellComponent is still null(or somehting else,depending when the field last updated it's value.
I mean, now that you told me that there is a "getCurrentValue",that is supposed to return correct value,I could do the validation through my custom validator,or I could inherit from TextField and "fix" it there, but this is kind of confusing - not to say that is looks like a bug to me.:)
Isn't the validator supposed to check the "current" value of the field?(at least when called explicitely through isValid()?)

Colin Alworth
21 Feb 2012, 1:30 PM
Right, sorry, I should have read your post in more depth.

We get to balance auto-validation's 'validate every keystroke' with the Editor Driver's 'validate only once at the end of the entire form', plus 'don't have the widget own the value so we don't duplicate code' and some pieces are getting lost in the shuffle trying to satisfy all three different goals.

If the feature you are after is validating while the user is typing, I'd encourage you to use setAutoValidate(true) - this is a built in feature we expect to work with Fields, and will work to make sure it is supported. As I think you've noticed, it is mentioned in other posts (at least three I think), and we do have an issue filed internally to make sure it works.

Our goal right now is to make sure that all present and future features that we will want out of 3 are possible with the API we have now. Bugs are a priority insofar as they interfere or cloud API issues, or if they stop components from fundamentally working. For issues where there remains a workaround and no API changes are projected to fix, we are deferring for the time being.

If you can confirm that GXT 2's autoValidate is enough for your use case, I'll double check that it is just a matter of modifying its behavior to use getCurrentValue in certain cases, and there just for the ValueBaseField subclasses.

IgyBoy
22 Feb 2012, 5:45 AM
Hi Colin,

autoValidate that works on getCurrentValue method instead of getValue would be perfect.

Currently,autoValidate also suffers from the same problem described above,so if you could modify it to work on getCurrentValue that would be perfect.

Tnx,
Igor

Colin Alworth
21 Mar 2012, 4:56 AM
AutoValidation should be working correctly in beta4 (sorry for the late update), see the symbol field at http://sencha.com/examples-dev/#ExamplePlace:basicbinding for a working example.

IgyBoy
28 Mar 2012, 9:19 AM
Sorry for the late reply,

I now have another problem...keypress doesn't fire when "enter" key is pressed.
I guess it is supposed to fire like any other key?! It was working in beta3.