prettyCheckable icon indicating copy to clipboard operation
prettyCheckable copied to clipboard

Disable & Enable states/methods

Open 0xadri opened this issue 10 years ago • 3 comments

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

0xadri avatar Jun 04 '14 12:06 0xadri

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!

arthurgouveia avatar Jun 04 '14 14:06 arthurgouveia

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 avatar Jun 05 '14 10:06 0xadri

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

0xadri avatar Jul 17 '14 08:07 0xadri