简体   繁体   中英

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;
  }
});

Set the field to readonly instead of disabled, then it will still be posted with the form data but will not be editable for the user.

 <label>disabled</label> <input type="text" disabled/> <label>readonly</label> <input type="text" readonly/> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM