View Full Version : Form and disabled fields: how to send their values anyway?

5 Sep 2012, 3:43 AM

I've made custom form with some fields.
When the user checks one checkbox, some other fields are disabled.
This is just visual, I still need to send all the values.

The problem is that


ignores disabled fields.

But I need to send them anyway. All my server code is based on the fact that I get all the fields. This is for homogeneous reasons (it's like that with all the other stuff with stores: I send all the fields)

onSave: function(){ var form = this.getForm();
if (form.isValid()) {
var data = form.getValues(false);
data.id = this.idPartenaire;
data = Ext.JSON.encode({ data: data });
headers: {
'Content-Type': 'application/json'
url: '/json/gestion/item/partenaire/',
method : 'POST',
jsonData : data,
params : {
mode: 'update'
success: function(form, action) {
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.action.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'blabla');
case Ext.form.action.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax failed');
case Ext.form.action.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);

How can I get the values even if they're disabled?

I'm talking about a generic and proper way, because my workaround is like that:

if (form.isValid()) {
var data = form.getValues(false);
var form = this.down('form').form;
data.livraison = (form.findField('livraison').checked ? 1 : 0);
data.livraison_delai = form.findField('livraison_delai').value;

data = Ext.JSON.encode({ data: data });

5 Sep 2012, 3:48 AM
what if you use readOnly instead of disabled? you can change a field to read only using the setReadOnly method:


where readOnly would be a boolean value to set or unset the readOnly state of the field.

5 Sep 2012, 4:03 AM
I've tried it, but is doesn't appear "grayed" and the user interaction is "broken" (= the user doesn't know he can't change it).

And when the user clicks on the other checkbox (the one that 'grays' the other ones), there's a feeling that nothing happened, because there's visually no change (= the use may try to modify some values, and because they became readonly this won't work, which may be very confusing).

5 Sep 2012, 4:11 AM
but if this works by getting the values of those fields, then you can use it. you can change the css class of the fields to 'x-item-disabled' using addCls method (and removeCls to change it back to normal)