Results 1 to 9 of 9

Thread: validator in combobox not marking field invalid

  1. #1
    Ext JS Premium Member
    Join Date
    Jan 2012
    Posts
    138
    Answers
    3

    Question validator in combobox not marking field invalid

    Hello ,
    I am using validator config for one of the combobox in my form and it has a save button bound to it too , so in case if validation fails 'Save' would be disabled. Problem is i am always gettign the validator executed but few of the times it doesnt mark the combobox as invalid and neither will provide the error message but Save will be disabled !
    Here is the code -
    Code:
     {
              xtype: 'combo',
              id: 'dlh_field',
              editable: false,
              fieldLabel: "Field",
              allowBlank:false,
              queryMode:'local',
              triggerAction: 'all',
                lastQuery: '',
              store: Ext.create('Ext.data.Store', {
                fields: ['profile', 'field'],
                data : []
              }),
              msgTarget:'under',
              displayField: "field",
              valueField: "field",
              disabled : true,
              validator:function(val){
                console.log('in Field validator..'+val);
                if(Ext.isEmpty(val)){
                    return IA.util.LocaleMgr.get('requiredErrorMsg');
                }
                else
                    return true;
            }
    Thanks
    Last edited by tobiu; 28 Feb 2012 at 7:18 AM. Reason: please use code tags!

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    So when it hits the validator and returns the string, the field doesn't even have the red invalid lines? Have not see that.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Ext JS Premium Member
    Join Date
    Jan 2012
    Posts
    138
    Answers
    3

    Default

    no , there are no red lines also

  4. #4
    Ext JS Premium Member
    Join Date
    Jan 2012
    Posts
    138
    Answers
    3

    Default

    re sending the code with more details -
    code for the two combo boxes :
    //Profile ( profile selection listener only works the first time! )
    {
    xtype: 'combo',
    id: 'dlh_profile',
    editable: false,
    fieldLabel: "Profile",
    queryMode:'local',
    store: Ext.create('Ext.data.Store', {
    fields: [ 'name'],
    data : []
    }),
    displayField: "name",
    valueField: "name",
    msgTarget:'under',
    validator:function(val){
    if(Ext.isEmpty(val)){
    return IA.util.LocaleMgr.get('requiredErrorMsg');
    }
    else
    return true;
    },
    listeners:{
    select: function(combo, records, opts){
    var profile = records[0].data.name ;

    Ext.getCmp('dlh_field').enable();
    Ext.getCmp('dlh_field').store.clearFilter(false);
    Ext.getCmp('dlh_field').store.filter('profile', profile);
    this.parentPanel.setDirty(true);
    }
    }

    },

    //Field
    {
    xtype: 'combo',
    id: 'dlh_field',
    editable: false,
    fieldLabel: "Field",
    allowBlank:false,
    queryMode:'local',
    triggerAction: 'all',
    lastQuery: '',
    store: Ext.create('Ext.data.Store', {
    fields: ['profile', 'field'],
    data : []
    }),
    msgTarget:'under',
    displayField: "field",
    valueField: "field",
    disabled : true,
    validator:function(val){
    if(Ext.isEmpty(val)){
    return IA.util.LocaleMgr.get('requiredErrorMsg');
    }
    else
    return true;
    },
    listeners:{
    select: function(combo, records, opts){
    this.parentPanel.setDirty(true);
    }


    }
    }
    ***************
    code for save method , i had to put this because initially the comboboxes doesnt have any value selected and validator on them will be triggered only when a change is detected , so in case user justs clicks on save then the validation should be re run .
    save : function()
    {
    var validatnPass = true;

    if(Ext.getCmp('dlh_profile').isValid()){
    if(!Ext.getCmp('dlh_field').isValid())
    validatnPass = false;
    }
    else
    validatnPass = false;
    if(validatnPass){
    this.callParent(arguments);
    }

    }

    Is user doesnt slect any value and clicks save , first validation for profile' combo box is done and once pass it moves to combo box 'field' . If validation on 'profile' fails i can see red lines with the message but if validation for 'field' combo box fails then 'Save' button is disabled but no red lines or error message is displayed !! I have to click on the combo box and then outside of it to get the message ! but since the validation (in save method) is failing there should be an error message shown .

  5. #5
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751
    Answers
    130

    Default

    why are you using
    Code:
    allowBlank:false
    combined with an validator that checks for the same thing? without your validator, the field should already get marked red when the validation event triggers (keyup, blur, etc.).

    i would try it without the config to check if there are differences. the custom validation should get applied first.
    Best regards
    Tobias Uhlig

  6. #6
    Sencha Premium Member
    Join Date
    Sep 2010
    Posts
    128

    Default

    I had a similar problem, and my msgTarget and anchor were not set correctly... would not hurt to double check your code

    -Tod

  7. #7
    Ext JS Premium Member
    Join Date
    Jan 2012
    Posts
    138
    Answers
    3

    Default

    Thanks Tod for replying to the thread :-)
    Can you share the msgTarget and anchor details , as to what were they before and what change you did.

  8. #8
    Ext JS Premium Member
    Join Date
    Jan 2012
    Posts
    138
    Answers
    3

    Default

    Thanks Tobiu for replying to the thread :-)
    I removed the allowBlank : false , but still seeing the issue

  9. #9
    Sencha Premium Member
    Join Date
    Sep 2010
    Posts
    128

    Default

    Quote Originally Posted by shailykamboj View Post
    Thanks Tod for replying to the thread :-)
    Can you share the msgTarget and anchor details , as to what were they before and what change you did.
    My problem was rather silly, and it affected TextField, not a combobox, so most likely I'm not helping at all... I simply did not have values for the msgTarget and anchor when I thought I did (variables did not exist). Having both was important for me to see validation (msgTarget: 'under', and anchor: '-0'.

Posting Permissions

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