Results 1 to 3 of 3

Thread: Marking a textfield invalid

  1. #1
    Sencha User
    Join Date
    Mar 2007
    Posts
    186

    Default Marking a textfield invalid

    I searched for this before posting, and while I found a few similar questions, none of them had any/satisfactory answers. So if I missed something, I apologize.


    I have two textfields, we'll just call them A and B. Field B is required only on certain values of A. I had a couple ideas on how to accomplish this, but both are presenting me with issues.

    The first idea was to set an onBlur listener on field A that calls "markInvalid()" on field B when necessary. However, this presents a problem since "markInvalid()" is visual only, it doesn't actually "mark" the field invalid to stop the form from being submitted (it seems to me that it should).

    The second idea was to write a custom validator for field B which checks the value of field A to handle it. However, this presented a different problem. A custom validator overwrites any automatic validators that would have run. For instance, field B also has an input regular expression mask, and the maxlength option set. Setting a custom validator effectively clears these.

    So, how can I either: 1 - truly mark a field invalid so that the form's validation check fails on submit, or 2 - write a custom validator function that still calls all previously set validations?

    Or, is there a 3rd option I haven't considered?

  2. #2
    Ext JS Premium Member pavanextjs's Avatar
    Join Date
    Jul 2008
    Posts
    118

    Default

    PHP Code:
    A.on('change', function(fieldnewValueoldValue){
    B.allowBlank false;
    B.validate();
    }); 
    'change' event is fired just before the 'blur' event only if the value is actually changed, meaning 'change' won't fire for tab-in & tab-outs.

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Posts
    186

    Default

    Awesome, that worked. Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •