dimanche 22 mars 2015

Ext js: submit disabled fields as blank

I have a form where depending on the value in field 'a', an optional field 'b' is enabled/disabled.


If data is submitted with an a-value where b is enabled, the database contains a value for b as well. The problem is that when the user then edits that record, selecting an a-value where b is disabled, I want the submit to submit a 'blank' value (empty string) in order to clean the database record.


(please do no argue that the backend should be intelligent enough to discard the b value in that case ... since that is out of my control)


I tried to enable the b-field and setting it to '' before submitting, but the b-field still isn't submitted. (using the on-beforeaction-submit)


I even tried to fiddle with other parameters (like originalValue) to make sure the b-field is dirty. I even tested with a random value (for the setValue call), just to make sure it's not a 'blank' field behaviour. But even when setting 'X' , the value isn't submitted. Nothing helps.


I'm sure i'm overlooking something really trivial, but I can't figure it out. So after spending hours to find out reading through posts and testing, I give up and address to the community.


Thx, C.



form.on('beforeaction', function(form, action) {
if (action.type == 'submit') {
//clean disabled fields before submitting
if (item!='general') {
var escid = Ext.getCmp('spcway-' + item + '-form-escid');
if (escid.disabled) {escid.enable(); escid.originalValue='abc'; escid.allowBlank=true; escid.setValue(''); escid.allowBlank=false}
if (item!='status') {
var escoption = Ext.getCmp('spcway-' + item + '-form-escoption');
if (escoption.disabled) {escoption.enable(); escoption.originalValue='abc'; escoption.setValue('')}
}
}
return true;
}
});

Aucun commentaire:

Enregistrer un commentaire