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

Disable & Enable states/methods #77

Open
0xadri opened this issue Jun 4, 2014 · 3 comments
Open

Disable & Enable states/methods #77

0xadri opened this issue Jun 4, 2014 · 3 comments

Comments

@0xadri
Copy link

0xadri commented Jun 4, 2014

Hi,
First, thank you for this great javascript library.
You do have methods to switch from & to "enable/disable".
However, there is no method to switch from & to "readonly/readwrite".

The problem I have here is that switching a input field to "disable" means that it is NOT sent on submit.
Whereas in my case I do want to sent it on submit, hence i want to use "readonly".

Any tip for this?

Introducing a new method might make sense, such as $('#myInput').prettyCheckable('readonly');

See this great SO question regarding "difference between disabled=“disabled” and readonly=“readonly” for HTML form input fields": http://stackoverflow.com/questions/7730695/whats-the-difference-between-disabled-disabled-and-readonly-readonly-for-ht

@arthurgouveia
Copy link
Owner

Hello, @adrien-be. It makes total sense.

I'm not sure when I'll be able to get back to this, anyway. Do you think you could give it a try?

Thanks!

@0xadri
Copy link
Author

0xadri commented Jun 5, 2014

Hi,
I will see what I can do regarding submitting a fix for this.
Meanwhile, here is a concept for a temporary solution:

// 1. make checkbox writable & style it as enabled
$("input[type=checkbox]").prop( "readonly", false );
$("input[type=checkbox] + a").removeClass("disabled")

// 2. make checkbox readonly & style it as disabled
$("input[type=checkbox]").prop( "readonly", true );
$("input[type=checkbox] + a").removeClass("disabled").addClass("disabled");

@0xadri
Copy link
Author

0xadri commented Jul 17, 2014

Hi again Arthur,

I just came across this strange fact yesterday "Inputs of type checkbox & inputs of type radiobutton MUST ignore the readonly attribute"

"How weird!" I thought... following thought being "Oh well, it's an HTML spec after all, why am I surprised?".

The thing is, there is a real need for this feature, as in, there are cases where you do want your checkbox/radiobutton to be displayed and its value submitted BUT not have it editable (just like other readonly input types, right?). Just have a look at the links in the "read more" section & see how many people actually answered/voted/viewed on these pages.

Hence I would support the idea of supporting this readonly mode, and:

  • mention how great this added feature is : adds more flexibility & possibly simplifies code in both front-end & back-end
  • but still indicate that this is not a standard (ie. if removing prettyCheckable in the future you need to mind that your checkbox will be editable even if they have a readonly attribute).

Read more:
http://www.w3.org/TR/html401/interact/forms.html#h-17.12.2
http://stackoverflow.com/questions/1953017/why-cant-radio-buttons-be-readonly
https://bugzilla.mozilla.org/show_bug.cgi?id=88512
http://stackoverflow.com/questions/155291/can-html-checkboxes-be-set-to-readonly
http://www.sitepoint.com/forums/showthread.php?963049-Read-only-Radio-Buttons

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

2 participants