Results 1 to 7 of 7

Thread: field validation to ensure that at least one of two fields is entered.

  1. #1
    Touch Premium Member
    Join Date
    Jul 2010
    Posts
    36

    Default field validation to ensure that at least one of two fields is entered.

    Hi all, i have 2 fields on an extjs form. Whats the best way to use ExtJS validation to ensure that at least one (either) of the fields is populated?

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Have a look at the advanced vtypes example in the SDK (it has a validator for two datefields).

  3. #3
    Touch Premium Member
    Join Date
    Jul 2010
    Posts
    36

    Default

    mmm, I did that Condor but its different in the sense that it fires off the validation when both fields are populated or where one is then the user starts typing in the other... I guess i need my validation to regardless of keypress etc... truth is i'm not getting the initialFieldPass stuff... i'll dig a bit more in the docs.

  4. #4
    Touch Premium Member
    Join Date
    Jul 2010
    Posts
    36

    Default

    my Vtype hello world... can anyone see what i need to add/change to get something to fire

    Ext.apply(Ext.form.VTypes,
    {
    contactNumberCheck : function(val, field) {
    return false;
    },
    contactNumberCheckText : 'error text'
    });

    // defined form panel
    {
    xtype : 'textfield',
    id : 'phoneMobile',
    fieldLabel : 'Mobile Number',
    vtype: 'contactNumberCheck'
    allowBlank: false
    }

  5. #5
    Touch Premium Member
    Join Date
    Jul 2010
    Posts
    36

    Default

    ok, different question. I'm gonna attach the test at the point when the form is submitted. Is there a way to 'fire' the validation formatting that puts the red underline and error message. I'm sure this isn't the best way to do it but it will suffice until a better solution could be understood.

  6. #6
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Example using validators instead of vtypes (maybe you understand this one better):
    Code:
    {
        xtype: 'textfield',
        fieldLabel: 'Field 1',
        itemId: 'field1',
        validator: function(value){
            if (!value && !this.ownerCt.getComponent('field2').getValue()) {
                return this.blankText;
            }
            return true;
        }
    },{
        xtype: 'textfield',
        fieldLabel: 'Field 2',
        itemId: 'field2',
        validator: function(value){
            if (!value && !this.ownerCt.getComponent('field1').getValue()) {
                return this.blankText;
            }
            return true;
        }
    }

  7. #7
    Touch Premium Member
    Join Date
    Jul 2010
    Posts
    36

    Default

    yep, thats done the job ... for whatever reason i dont know but the Vtype validation seemed to be ignored on the client validation check (that you also helped with..i.e
    mainForm.on('clientvalidation',function(f, valid)
    { Ext.getCmp('submitForm').setDisabled(!valid); }

    all other field validation disabled submit apart from 'custom' vtypes that were applied!?

    Either way, this works great, thanks again.

Similar Threads

  1. EditorGridPanel: data entered is lost on failed validation
    By Event Horizon in forum Ext 2.x: Help & Discussion
    Replies: 25
    Last Post: 17 Sep 2012, 7:19 AM
  2. Validation of form fields
    By prasad508211 in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 23 May 2010, 7:07 AM
  3. TextField Validation - Validation Fired as soon as user clicks into Field - bug?
    By jfisher in forum Ext GWT: Help & Discussion (1.x)
    Replies: 0
    Last Post: 29 Sep 2008, 9:25 AM
  4. [ComboBox] submitting selected field / user entered text
    By Zyclops in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 22 Aug 2007, 4:06 AM

Tags for this Thread

Posting Permissions

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