-1
By dynamically including an item in table
, I want to leave the field cbempresa
with the readonly=true
and when there are no items in the table
he needs to be readonly=false
, logic works when I use disabled
, but readonly
nay.
Go on like I’m doing:
$("#cbempresa").prop("readonly", true);
And here is to remove the readonly
:
$("#cbempresa").prop("readonly", false)
I thought it was something I was doing wrong, but by putting disabled
works.
It should work. Maybe the context is preventing something.
– Sam
Mariana, could you inform in your question how is the inclusion of a new item (Is the inclusion of a new row in the table?, how it is made?) and if possible also tell us what element of html is "cbempresa" because there are elements that are not compatible with the
readonly
such as the<select>
– Caique Romero
@Sam this happens, when I’m adding data dynamically into
table
, thought it might be something that was preventing, but because it would prevent the readonly and would not prevent the disabled?– Mariana
@Caiqueromero the input is
select
so it doesn’t workreadonly
?– Mariana
The element
<select>
does not have the attributereadonly
, see here. And the attributereadonly
does not receive a valuetrue
orfalse
, if it is present, the element is read only, if it is not present it is not, see here.– Pedro Gaspar
I think there is a question with this scenario. I’m trying to find here.
– Sam
Take a look here: https://answall.com/a/273982/8063
– Sam
@Sam but in this case may confuse the user, because the value will be of another that he selected, however it can change, it is not that, or got it wrong ?
– Mariana
Mariana, in the example I showed, the user can open select but cannot change the selected option. It would be an emulation of
readonly
, since in thedisabled
the user can’t even open select.– Sam
Sorry for the delay, just for clarification, select and input are different elements. Peter has already answered your question and left excellent references for a better understanding. Now on how to deal with this situation, if you really need to use one
select
you can simulate areadonly
when removing possible user interactions with the field, follow the link with a few suggestions: https://answall.com/questions/128188/como-aplica-readonly-em-um-select– Caique Romero