PDA

View Full Version : [1.2.3] A ComboBox is invalid after an initial bind



sdc
24 Feb 2009, 6:12 AM
- GXT version : 1.2.3
- Hosted mode
- Operating System : Windows XP
- Detailed description of the problem :

I have a form panel which I want to bind to a bean. One of the bean properties is bound to a ComboBox which do not accept blank values.
When I init my form, I bind an initial bean containing null attributes. So the bind call set fields value to null. But since this call is made in a DeferredCommand, it will call ComboBox.setValue after the ComboBox is rendered. So, it will call setRawValue() and the combo box will be marked invalid.

- Sample code which simulates the use case :

public class TestComboBoxWithNullValue implements EntryPoint {
public void onModuleLoad() {
Dialog dialog = new Dialog();
dialog.setSize(600, 400);
FormPanel formPanel = new FormPanel();
final SimpleComboBox<String> comboBox = new SimpleComboBox<String>();
comboBox.setAllowBlank(false);
DeferredCommand.addCommand(new Command(){
public void execute() {
comboBox.setValue(null);
}
});
comboBox.add("First");
formPanel.add(comboBox);
dialog.add(formPanel);
dialog.show();
}
}

sven
24 Feb 2009, 6:22 AM
If allowBlank is false and you setup a value that is not valid, it is normal that the field is invalid or not?

sdc
24 Feb 2009, 6:38 AM
Actually, the issue affects Field, not only ComboBox.

Actually, I do not explicitly setup a null value. I have an object which initially contains null attributes. I bind this object to a form panel so that the user can edit it and when the form is valid, I can send the object to the server. But the FieldBinding.bind is called in a deferred command and then sets the null value AFTER the field is rendered. I don't think the fields should be initially marked invalid before the user can do anything. And it was not the case in previous versions. Do you understand my problem or do you want me to post a more complete code ?

sdc
24 Feb 2009, 6:45 AM
public class Test implements EntryPoint {
public void onModuleLoad() {
Dialog dialog = new Dialog();
dialog.setSize(600, 400);
FormPanel formPanel = new FormPanel();
Customer newCustomer = new Customer(); //initial object containing null attributes
BeanModel newCustomerModel = BeanModelLookup.get().getFactory(Customer.class).createModel(newCustomer);
TextField<String> nameField = new TextField<String>();
nameField.setAllowBlank(false);
FormBinding binding = new FormBinding(formPanel,false);
binding.addFieldBinding(new FieldBinding(nameField,"name"));
binding.bind(newCustomerModel); //this will setValue(null) in a deferred command -> after the form is rendered, so it will be marked invalid
formPanel.add(nameField);
//when the user will click on OK button, I will send the object to the server if the form is valid
dialog.add(formPanel);
dialog.show();
}
}

sven
24 Feb 2009, 6:46 AM
The code works as it should. You setup an invalid value and the field gets markedinvalid. That is correct.

sdc
24 Feb 2009, 6:49 AM
Did you look at the new sample code ?

sven
24 Feb 2009, 6:50 AM
Yes i looked at it. Also there you have allowblank set to false.

sdc
24 Feb 2009, 6:58 AM
Well, I think you don't understand because of my bad english.

Suppose you are going to a forum. You want to register so you go to the register form.
When you arrive to the register form page, all mandatory fields (username, password) are already marked invalid because they are empty, would you find it correct ?
This is my use case.

sven
24 Feb 2009, 7:01 AM
I understand what you mean. But what is happening is really what is intended to happen. You can clear the invalid status from the field. Or you can override FieldBindind in that why, that it doesnt set a nullvalue (doesnt call setValue(null) on the field))

sdc
24 Feb 2009, 7:36 AM
what is happening is really what is intended to happen.
So I don't understand why I didn't have such issue in any previous version ? Is it an enhancement :-/ Also, this is not the first issue related to this API change (use of a deferred command) : http://extjs.com/forum/showthread.php?t=60494


You can clear the invalid status from the field.Well... I'll do it in another deferred command... but for me it really looks like a workaround. :(


Thanks for the quick replies.

Cheers

sdc
24 Feb 2009, 8:01 AM
http://extjs.com/forum/showthread.php?p=293656