Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readonly attribute is ignored #218

Open
guojuan999 opened this issue Nov 11, 2019 · 3 comments
Open

readonly attribute is ignored #218

guojuan999 opened this issue Nov 11, 2019 · 3 comments

Comments

@guojuan999
Copy link

guojuan999 commented Nov 11, 2019

<input type="checkbox" readonly="readonly" id="test"><label for="test">Change</label> $('input').bootstrapSwitch();

The check box should be readonly but if you click the labe; "change" then the check box is updated.

@prathmeshnaik91
Copy link

Hi @guojuan999 ,
You need to use disable attribute instead of readonly. Final code block should look like this,

<input type="checkbox" id="test"><label for="test">Change</label> $('#test').bootstrapToggle('disable');

@BikeMrown
Copy link

Just some extra info... The above is correct that there is no readonly for checkboxes and that the recommendation is to use disable/enable instead. However, a disabled checkbox will not submit the value on a POST. The best option I have found is to add a second "dummy" property to your viewmodel and use it as your checkbox, set the actual value to a hidden input and have the dummy update the hidden "actual" on flag change and such. The hidden input will always submit on the POST.

@qinjunjerry
Copy link

Thanks for the tip of $('#test').bootstrapToggle('disable')
Another easier way to make checkbox readonly is to add to the checkbox:onclick="return false;"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants