Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Chosen Dropdown Read only (not disabled)

I'm looking to make a chosen dropdown menu read only, and I need to do this dynamically using a jQuery selector. If I set it to disabled using:

$("#dropdownDepartment").attr("disabled","disabled").trigger('chosen:updated');

the value isn't POSTed but I need it to be.

I have tried

$("#dropdownDepartment").attr('readonly',true).trigger('chosen:updated');

but this doesn't work.

I'm using Chosen v1.4.2 and jQuery v2.1.4.

Help appreciated! Thank you.

like image 852
Robin Avatar asked Jun 03 '15 12:06

Robin


People also ask

How do you make a dropDown Uneditable?

You need to add a "disabled" property to the form dropdown class.

Can a dropDown be readonly?

Dropdown (select element) is always read only. User do not edit it. User can select any of the option of its own chice. Unlike other html elements, it dont have a attribute which can make the element readony and prevent users to change its value.


1 Answers

The best solution for me was such an ugly trick $("#dropdownDepartment").prop('disabled',true).trigger('chosen:updated').prop('disabled',false). So chosen is disabled but value from select is POSTed.

like image 143
Илья Стельмаков Avatar answered Nov 16 '22 00:11

Илья Стельмаков