1. #1
    Ext User
    Join Date
    Sep 2008
    Posts
    39
    Vote Rating
    0
    lazyProgrammer is on a distinguished road

      0  

    Default Form Validation when one field is dependent on another form field

    Form Validation when one field is dependent on another form field


    HI All,

    I have one form in which I have one combo box (Combo) and another text box(Text) which is enabled on certain values selected of combo box.I need to submit the form and validate manadatory field on Text if it is enabled. I have defined allowBlank : false for both Combo and the Text. and also I have added addForm.getForm().isValid() before submitting the form.
    My problem is that when Text is enabled the validation works perfectly and red line is shown if Text is empty but when Text is disabled then also red line is shown though value of addForm.getForm().isValid() is true.

    Can someone help me out how to get rid of that redline (sign of mandatory field).

    Thanks.

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    formPanel.getForm().isValid() should clear the invalid mark on all disabled fields.

    However, field.isValid() doesn't do this (use field.validate() instead).

  3. #3
    Ext User
    Join Date
    Sep 2008
    Posts
    39
    Vote Rating
    0
    lazyProgrammer is on a distinguished road

      0  

    Default


    Quote Originally Posted by Condor View Post
    formPanel.getForm().isValid() should clear the invalid mark on all disabled fields.

    However, field.isValid() doesn't do this (use field.validate() instead).
    Hi Thanks a lot for quick reply!

    But formPanel.getForm().isValid() is not clearing invalid mark. I have tried to reset the form and disable and applied the fieldLabel for the Text.


    addForm.getForm().isValid();
    addForm.getForm().reset();
    otherText.setDisabled(true);
    Ext.getCmp('otherText').setFieldLabel('Set new label');


    Though it is giving the desired result but not sure whether this is the correct approach!

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    field.reset() and form.getForm().reset() clear the invalid mark, but I still say that form.getForm().isValid() should also do this!

    Could you post a small example that demonstrates the problem?

  5. #5
    Ext User
    Join Date
    Sep 2008
    Posts
    39
    Vote Rating
    0
    lazyProgrammer is on a distinguished road

      0  

    Default


    Hi this is the code snippet where I was facing the problem :

    addForm = new Ext.FormPanel({
    frame: true,
    monitorValid:true,
    bodyStyle: 'padding:5px 5px 0',
    items: [{
    layout: 'column',
    items: [{
    layout: 'form',
    columnWidth: 0.5,
    items:[otherCombo,otherText]
    }]
    }],
    buttons: [{
    text: 'Add',
    id:'addBtn',
    formBind:true,
    handler: function(){
    if(!addForm.getForm().isValid()){
    return false;
    }
    }]
    });


    var otherText=new Ext.form.TextField({
    fieldLabel: 'Other',
    autoCreate : {tag: 'input', type: 'text', maxlength: '50', autocomplete: 'off'},
    id: 'otherText',
    allowBlank:false,
    anchor:'80%'
    });


    I hope Combo's code is not required here for the example.

  6. #6
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    1. I removed monitorValid:true.
    2. I changed the handler to:
    Code:
    otherField.setDisabled(true);
    if(!addForm.getForm().isValid()){
      ...
    }
    3. No invalid mark appears.

  7. #7
    Ext User
    Join Date
    Sep 2008
    Posts
    39
    Vote Rating
    0
    lazyProgrammer is on a distinguished road

      0  

    Default


    Quote Originally Posted by Condor View Post
    1. I removed monitorValid:true.
    2. I changed the handler to:
    Code:
    otherField.setDisabled(true);
    if(!addForm.getForm().isValid()){
      ...
    }
    3. No invalid mark appears.

    Hi thanks again for quick response!
    But do u mean to say that monitorValid:true is not required in form validation? Sorry for being such an ignorant in EXT JS.

  8. #8
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Quote Originally Posted by lazyProgrammer View Post
    But do u mean to say that monitorValid:true is not required in form validation? Sorry for being such an ignorant in EXT JS.
    No, that's not what I meant. monitorValid:true will regularly call isValid on all fields and enable/disable all bound buttons. It's not required, but a nice optional feature.

    I needed to remove monitorValid, otherwise I could not click the button when the field was invalid (just for the example).

  9. #9
    Ext User
    Join Date
    Sep 2008
    Posts
    39
    Vote Rating
    0
    lazyProgrammer is on a distinguished road

      0  

    Default


    Okay...I think I got you point. Thanks a lot for your prompt reponses and support

Thread Participants: 1