i doing form validations in sencha touch 2.3. model looks following.
ext.define('net.omobio.dialog.dialogcc.model.stocktransferdetails', { extend: 'ext.data.model', config: { fields: ['to_msisdn','to_profile_id','transfer_lob','transfer_item_status','transfer_product','transfer_qty','transfer_req_type','transfer_item_type','transfer_pack_type'], validations: [ { type: 'presence', field: 'to_msisdn' }, { type: 'presence', field: 'to_profile_id' }, { type: 'exclusion', field: 'transfer_lob', list: ['null'] }, { type: 'exclusion', field: 'transfer_req_type', list: ['null'] }, { type: 'exclusion', field: 'transfer_item_type', list: ['null'] }, { type: 'exclusion', field: 'transfer_pack_type', list: ['null'] } ] } });
following code segment use in controller remove validations hidden form fields no luck.
var form1 = me.getstocktransferrequestpage(); var model = ext.create("net.omobio.dialog.dialogcc.model.stocktransferdetails", form1.getvalues()); // validate form fields var errors = model.validate(); if (!errors.isvalid()) { // loop through validation errors , generate message user errors.each(function (errorobj){ //errorstring += errorobj.getfield() + " " + errorobj.getmessage(); console.log('7777777777777777777 '+errorobj.getfield()); if (!ext.getcmp(errorobj.getfield().tostring()).ishidden()) { var s = ext.string.format('field[name={0}]',errorobj.getfield()); form1.down(s).addcls('invalidfield'); } }); ext.msg.alert('','stock_transfer.errors.required_fields_empty'); }
i appreciated if me solve this.
thank you
so there multiple ways achieve this, preference though folks won't it, work.
i did following override solve problem, tried best not affect normal flow of validation.the first 2 overrides have added somewhere overrides folder, have add them once whole app.
ext.define('ext.form.field.baseoverride', { override: 'ext.form.field,base', /* traverse , hidden parent/ancestor */ isparenthidden: function () { return this.up('[hidden=true]'); } /* override isvalid basic method consider skipvalidatewhenhidden property, when skipvalidatewhenhidden set true code should check if elementor it's parent/ancestors hidden */ isvalid: function () { var me = this, disabled = me.disabled, ishidden = me.ishidden(), skipvalidatewhenhidden = !!me.skipvalidatewhenhidden, validate = me.forcevalidation || !disabled, isvalid = validate ? me.validatevalue(me.processrawvalue(me.getrawvalue())) : disabled; if (isvalid || !skipvalidatewhenhidden) { return isvalid; } if (skipvalidatewhenhidden) { ishidden = ishidden ? true : me.isparenthidden(); if (ishidden) { return skipvalidatewhenhidden; } } return isvalid; } });
and you'll able following, set property true on field if not visible user, survive validation
{ itemid: 'city', cls: 'addresscity', xtype: 'textfield', emptytext: emptycitytext, skipvalidatewhenhidden: true, },
another approach add show()/hide() listener on fields container enable/disable children, disabling fields make them skip validation, i'm not big fan of managing button states , wiring listeners.
Comments
Post a Comment