PDA

View Full Version : Combobox mark invalid to not submit



brk11
5 Aug 2010, 6:42 AM
How can I mark as invalid a combobox? Because if I use markInvalid method I see the combo as invalid, but when it is submitted is valid!

Help, please!

Condor
5 Aug 2010, 6:46 AM
Marking a field as invalid is only temporary. Submitting the form will revalidate the field.

Instead of marking the field as invalid, you should write a validator (or vtype etc.) that would invalidates the field if it has this value.

brk11
5 Aug 2010, 6:50 AM
I tried to use a validator function but I get strange results...

brk11
5 Aug 2010, 6:55 AM
... first time validator returns false (invalid), combo is marked as invalid, but if I select the same value again I get the combo is valid. I get the same if I select another value... I show a text in a display field when I get an error and the display field shows the correct invalid message, so the validator function does what I expect!

Condor
5 Aug 2010, 6:57 AM
What kind of validation do you need to do?

brk11
5 Aug 2010, 6:59 AM
Depends on the selection, I get some values from server side and I have to compare them with some values in the form.

Condor
5 Aug 2010, 7:08 AM
Why not do the check on the server and return the error messages from the submit? That's the way forms were designed to work in Ext.

Another option would be to use the RemoteValidator plugin (http://www.sencha.com/forum/showthread.php?19112-New-Remote-Field-Validation-Plugin) (but I don't know if it still works on Ext 3.x).

brk11
5 Aug 2010, 7:16 AM
No, I can not do that, because when I select a value in the combobox I have to get some new data of the server and validate them with some numberfields in the form... But if I change the value of numberfields I also have to do the validation, but in this case I don't need to do the request to the server... So I can not
do the validation on server side...

So, I should be able to fire the validation of the combobox from the numberfields! That's the reason why I tried to use the markInvalid method...

Condor
5 Aug 2010, 8:07 AM
You try the following when the combobox should be marked invalid:
- Store the error message and the current value as a property in the combobox
- Write a validator method that checks if the value is still the same as the current value and returns the error message in that case (and otherwise true).
- Validate the combobox to show the message.