• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Validate user input against a list

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validate user input against a list

    Hello,

    My apologies up front, but it seems that the little things are kicking my butt.
    I need to be able to validate, on change or add, what the user inputs. As in Y or N for yes or no.
    It seems that this should be a list in the program because it will always be Y or N.
    I have tried the validator doing: type: 'inclusion', list: ['Y', 'N'] but only get errors.

    Thank you in advance for any help.

    Cliff

  • #2
    I was able to make some headway, today and found that I needed an event.
    Here is where I am now:
    Code:
                            {
                                xtype: 'textfield',
                                itemId: 'PRJFRL',
                                fieldLabel: 'From',
                                name: 'PRJFRL',
                                size: 1,
                                listeners: {
                                    validitychange: {
                                        fn: me.onPRJFRLValidityChange,
                                        scope: me
                                    }
                                }
                            },
    __________________________________________________________
       onPRJFRLValidityChange: function(field, isValid, eOpts) {
            var SWList = [' ', 'S', 'W'];
    
    
            if (jQuery.inArray(SWList, field.lastValue) != '-1') {
                alert('Found in Array');
            } else {
                alert('Error - Not in Array');
            }
    
    
        }
    But the jQuery does not work.
    I found the field.lastValue returns the input. So I want to validate against the Array SWList.
    Hopefully someon can point me in the correct direction.
    Thanks
    Cliff
    Last edited by sean.lanktree; 11-16-2015, 01:31 PM. Reason: code tags

    Comment


    • #3
      Well your off base with the jQuery validity check. We will post some instructions on how to do this with Valence/Ext JS shortly.

      Comment


      • #4
        You can provide a validator function:

        Code:
                xtype : 'textfield',
                allowBlank : false,
                enforceMaxLength : true,
                maxLength : 1,
                validator : function(val){
                    var validValues = ['S','W'],
                          val = Ext.util.Format.uppercase(val);
                    
                    if (Ext.Array.indexOf(validValues,val) != -1){
                        return true;   
                    } else {
                        return 'Some error to output';
                    }
                }
        However, this scenario would be better suited to a combo box since it is essentially having the user choose from a list of valid values.

        Comment


        • #5
          Great.

          Yes a combo box would be better, but I was not sure how to load the variables, except by input file.
          Thank you for the help.
          Cliff

          Comment


          • #6
            Hey Cliff,
            Here is a common combo box set up i use alot for one or two options to choose from like you're doing....
            it has an inline data array store, so there is no need for a backend file, etc....
            Code:
            {
                                        xtype: 'combobox',
                                        flex: 2,
                                        fieldLabel: 'Employed From (month/year)',
                                        labelAlign: 'top',
                                        labelWidth: 125,
                                        name: 'WRK1FROMMM',
                                        store: {
                                            fields: [
                                                'index',
                                                'text'
                                            ],
                                            data: [
                                                {
                                                    index: 1,
                                                    text: 'January'
                                                },
                                                {
                                                    index: 2,
                                                    text: 'February'
                                                },
                                                {
                                                    index: 3,
                                                    text: 'March'
                                                },
                                                {
                                                    index: 4,
                                                    text: 'April'
                                                },
                                                {
                                                    index: 5,
                                                    text: 'May'
                                                }
                                            ]
                                        },
                                        valueField: 'index'
                                    },

            Comment

            Working...
            X