Results 1 to 6 of 6

Thread: How to do conditional validation on combo box?

  1. #1

    Default How to do conditional validation on combo box?

    I have a problem that is conceptually pretty simple, but am having trouble finding a solution. Basically, I have a combo box which I want to be a required field BUT only if there are items in the list. IOW, if there's at least one item to select, the user must select one. However, if the list is empty, they don't have to select anything.
    • I can't set allowBlank to false in the config because that will always require a value.
    • I tried setting allowBlank dynamically, but this doesn't seem to work. Instead, when allowBlank is false, it still allows blanks.
    • I tried using plugin to do validation on blur. This only partially works. When the combo box loses focus, it will show the validation error message but when the user clicks submit, the error vanishes and form submits anyway.
    • I tried using a vtype. But vtypes only seem to perform validation if the combo box has a value. IOW, when the user hasn't typed or selected anything, the vtype isn't invoked.
    Does anyone have any ideas?

  2. #2
    Sencha User
    Join Date
    Nov 2009


    may be you must "disable" this combo box... something like:

    if  (ComboboxStore.getCount()==0) {

  3. #3
    Sencha User mschwartz's Avatar
    Join Date
    Nov 2008
    San Diego, Peoples' Republic of California


    If your form has no file upload field, you can serialize the form yourself and do the exact kind of validation you require along the way.

    By serialize the form, I mean:

    var serialized = {
      firstName: Ext.getCmp('firstName').getValue(),
      lastName: Ext.getCmp('lastName').getValue()
    if (serialized.firstName.trim().length == 0) {
      alert('Enter a first name!');
    // and so on.
    Then Ext.Ajax.request() to POST your serialized results.

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    The Netherlands


    A vtype doesn't get invoked for empty text fields, but the validator method does!

  5. #5


    Thanks, that works. For the benefit of others reading this thread, here's my code:

    var stateField = this.getForm().findField('StateCd');
    if (stateField){
     var store = stateField.getStore();
     // unrelated code omitted 
     var count = store.getCount();
     if (count){
     } else {
    Hopefully, our UX team won't complain about disabling the combo box.

  6. #6


    Thanks, I didn't know about the validator method. I'll keep that in mind in case there are any issues complaints.

Similar Threads

  1. [Solved]Conditional field validation
    By siebe vos in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 30 Dec 2010, 2:14 AM
  2. Validation problem with Combo in Ux.Wiz
    By MH61 in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 16 Jul 2009, 6:18 AM
  3. [SOLVED]COMBO Validation
    By kcireneg in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 22 Apr 2009, 10:07 PM
  4. [solved]Combo box and jquery validation help
    By cybertrip in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 31 Mar 2009, 7:15 AM
  5. Validation: Combo-Box-Value must be checked in CheckboxGroup
    By Dumas in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 5 Mar 2009, 7:23 PM

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