I am using lightning:input
of different types. Using readonly=true
in input of type text is working but does not work for checkbox
or for lightning:select
.
Anyone got any clue for this?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI am using lightning:input
of different types. Using readonly=true
in input of type text is working but does not work for checkbox
or for lightning:select
.
Anyone got any clue for this?
You may use attribute disabled
instead of readonly
.
Here's an example with lightning:input
[checkbox] and lightning:select
:
<div>
Checkboxes
<lightning:input type="checkbox" label="Red" name="red" checked="true" disabled="true"/>
<lightning:input type="checkbox" label="Blue" name="blue" disabled="true"/>
</div>
<br/>
<div>
<lightning:select name="selectItem" label="Select an item" value="2" disabled="true">
<option value="">choose one...</option>
<option value="1">one</option>
<option value="2">two</option>
</lightning:select>
</div>
HTML docs say that readonly
does not work for checkbox and that select does not have a readonly
attribute.
SELECT ... does not have a READONLY attribute. The reason is that technically lists don't have values... they have selected options, which themselves have values. You may wish to see , which disables the list.
It's important to understand that READONLY merely prevents the user from changing the value of the field, not from interacting with the field. For many types of fields, READONLY is irrelevent because you don't normally change the value. In checkboxes, for example, you can check them on or off (thus setting the CHECKED state) but you don't change the value of the field. DISABLED, however, actually prevents you from using the field. Notice in these examples that you can set the checkboxes even though they are "read only"
Both suggest using the disabled
attribute.
The readonly
attribute is not supported on input type="checkbox" - as you can see by fiddling around here:
https://jsfiddle.net/xue78fhd/
to stop a checkbox being fiddled you need to do add a little javascript event "hack" to the the onclick, like this: