PDA

View Full Version : Textfield setValue vs invalid



Jack9
30 Oct 2009, 11:45 PM
How do you setValue(''), as an example, an invalidated field without removing the invalid class? Should you check for invalid, apply the invalid class to the component (essentially setting the valid and invalid the same) or is there a less tricky way?

Jaitsu
31 Oct 2009, 3:38 AM
if you set the field with a value, surely the value you're setting won't be invalid?
if it is, then just validate it again after setting the value but I have no idea why you'd want to set an invalid value

Jack9
1 Nov 2009, 1:28 AM
The problem arises from a form submission.
failure:function(){...}
has a useful feature.
Without any code whatsoever in the failure function, the json returned:


{
success:false
,errors: {
field_name1:'Server says problem is X.',
field_name2:'Server says problem is X.'
}
}


Invalidates fields with the error message specified.
However, for sensitive data, like a password or captcha or ss# or phrase or any number of items, you will want to clear that field but not lose the failure tooltip or cause a very strange invalid->valid->invalid transition.
clearing the field

Jaitsu
1 Nov 2009, 3:57 AM
Sorry, I'm still not sure I follow you...

- You enter form data (including password)
- You submit to the server
- Server sends back errors
- Ext highlights form fields with errors

If your password fields meet the criteria set at both client side and server-side level validation then why would you want to mark the password as invalid?

Jack9
1 Nov 2009, 10:44 AM
Cases:

1.
User submits a field with a password 1 character long (invalid). There is no need for client side validation, since it can be bypassed anyways...

Server returns error. Password is obfuscated. Clearing, is a good action here. Now there is no error state information anymore.

2.
User submits a captcha that is invalid. There is no need for client side validation since the point is not to validate client side.

Server returns error. Next captcha will not be the same. Clearing, is a good action here. Now there is no error state information anymore.

Jaitsu
1 Nov 2009, 2:12 PM
You can do some custom client-side processing of the server response... just use the markInvalid() method on any fields that don't meet your criteria...

Other than that, you could change the default behaviour with an override, but is that really necessary seeing as Ext provides you with a way of marking a field as invalid anyway

Jack9
1 Nov 2009, 4:23 PM
You can do some custom client-side processing of the server response... just use the markInvalid() method on any fields that don't meet your criteria...
This is what I said. Clearing the field, causes invalidation to be cleared, then I would have to reinvalidate. This leads to a strange behavior where the field is invalid, valid, then invalid again. How would you avoid this? An override I guess.

Edit: The answer is to use setRawValue(''); - setting raw value bypassed validation/invalidation checking, leaving the initial state of validation/message intact.

Jaitsu
2 Nov 2009, 4:57 AM
that's good to know for future