indrarajw
indrarajw

Reputation: 198

'Ext Js' form field validation using 'validator'

Hi I'm very new to 'Ext JS' (about 4 days) and have to edit 'Ext JS' form. That form is to edit existing entry. So I have to update 'project name' field in this form and need to follow following conditions.

  1. Users can submit form with its old project name (old old project name means project name when form is load).

  2. When user select existing project name from suggestion drop down (except old project name), need to show error.

    Basic idea of this conditions is prevent duplicate project names.

So I try to do this with 'validator' but I can't find a way to compare old project name and new project name.

  1. Is there any method to compare those values ??
  2. Any other way to validate this field ???

this is what I have done so far...

_est.project.view.panel.updateprojectname.combox = function (projectdetails) {
var nstore = _est.project.view.panel.updateprojectnstore();
var combo = Ext.create('Ext.form.ComboBox', {
    fieldLabel: _est.project.text.nameText,
    store: nstore,
    labelSeparator: ' ',
    vtype: 'text',
    afterLabelTextTpl: _est.afterLabelTextRequiredTpl,
    msgTarget: 'side',
    displayField: 'projectname',
    valueField: 'projectname',
    labelWidth: 130,
    maxLength: 200
    name: 'projectname',
    allowBlank: false,
    pageSize: true,
    triggerAction: 'query',
    autoSelect: true,
    minChars: 0,
    itemId : 'project-name-field',
    value: Ext.htmlDecode(projectdetails.projectname),
    hideTrigger: true,
    anchor: '95%',
    validator: function(oldValue) {  
        var existnstore = Ext.StoreMgr.lookup("ptoject-project-names-get-store");
        if(existnstore){
            var nstore = existnstore.findExact('projectname',oldValue);
            if(nstore < 0){
                return true;
            }else{
                return 'Job name already exist.';
            } 
        } 
    },
    listConfig: {
        getInnerTpl: function () {
            return '<a class="search-item">' +
                    '<span>{projectstate}</span>' +
                    '{projectname}' +
                    '</a>';
        }
    }, 
});
return combo; 
}

any suggestions or opinions to do this :) thanks in advance..

Upvotes: 2

Views: 5429

Answers (1)

indrarajw
indrarajw

Reputation: 198

I change 'validator' function and this work for me

    validator: function(Value) {   
        var existname = projectdetails.projectname; 
        if(Value !== existname){
            var existnamestore = Ext.StoreMgr.lookup("update-ptoject-project-names-get");
            if(existnamestore){
                var namestore = existnamestore.findExact('projectname',Value);
                if(namestore < 0){
                    return true;
                }else{
                    return 'Job name already exist. Please select different job name.';
                }
            }
        }
        return true; 
    }

Upvotes: 3

Related Questions