Why readonly property of lightning: input not working?

2.4K    Asked by JacobRutherford in Salesforce , Asked on Aug 17, 2021

 I am using lightning: input of different types. Using readonly=true in the input of type text is working but does not work for checkbox or for lightning:select.

Why input readonly property of lightning not working? Did anyone get any clue for this? Pls suggest any solution.

Answered by Miura Baba

You may use attribute disabled instead of input readonly.

Here's an example with lightning:input [checkbox] and lightning:select:

     Checkboxes       choose one... one two  

HTML docs say that readonly does not work for checkbox and that select does not have a readonly attribute.

Doc for select:

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.

Doc for checkbox:

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.



Your Answer

Interviews

Parent Categories