0

So i am using jquery mobile and i have a checkbox and label in a form like so :

<form class="myForm">
  <label><input checked name="myCheckBox" id="myCheckBox" onclick="return false;" onkeydown="return false;" type="checkbox">Checking</label>
</form>

Now comes my question: How can i make the checkbox readonly ? So the user can click on it but it wont change its state? I dont want to use the disabled option!

NOTE: Before you mark it as a duplicate ive searched for answers and could only find solutions using none jquerymobile checkboxes. They solved it with: onclick="return false" which is not working... in jquerymobile you can test it with this fiddle. If you remove the external resources onclick="return false" is working.

5
  • I dont want to use the disabled option! Why? What you're trying to achieve is the exact purpose of that option. Commented Sep 27, 2016 at 14:34
  • I dont want to use it because it will be grayed out. Can i avoid that? Commented Sep 27, 2016 at 14:37
  • 1
    I see. I'll have a look. Commented Sep 27, 2016 at 14:38
  • It's does not appear to be easy to do -- even preventing the default vclick behavior fails to work (probably because the original checkbox is not part of the final widget). ezanker's solution should work, though. Commented Sep 27, 2016 at 14:46
  • Yea it does, thanks for beeing cool though Commented Sep 27, 2016 at 14:48

1 Answer 1

2

You can use disabled and then override the CSS that grays the checkbox:

.myForm .ui-checkbox.ui-state-disabled {
  opacity: 1;
}

jQM applies opacity to the DIV that surrounds the enhanced checkbox. This CSS resets the opacity to 1.

Updated FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.