A.W.
A.W.

Reputation: 3021

ExtJS - submitting disabled checkbox

Version 4.2.1

In a form I use a checkbox which should not be changed for a certain type of user. So I disable the checkbox and set checked and value to `true. I want this value to be submitted.

        {
          name: 'myName',
          itemId: 'myItemId',
          xtype: 'checkboxfield',
          fieldLabel: "test",
          checked: true,
          value: true,
          disabled: true,
        }, 

When I submit the form I see that there is no parameter for this checkbox.
Only when I set disabled to true I get a parameter with value on

When I look at:

    var data = form.getValues();
    console.log(data);

this checkbox is not submitted with an on value.

When I use readonly: true I can check/uncheck the checkbox and that value is submitted.

So how can I disable the checkbox for editing, set the value to checked and get it submitted to the server?

Upvotes: 2

Views: 2807

Answers (1)

A.W.
A.W.

Reputation: 3021

Found this thread from 2008/2009 which has a simple solution.

Form Submit is not sending values of disabled field
Sending disabled field

This code sets the checkbox to readonly is shown and a user cannot change the value. And the field is submitted to the server.

readOnly: true,
fieldClass: "x-item-disabled"

Upvotes: 3

Related Questions