25/10/2011

jQuery readonly drop downs

Normally in SharePoint we would render a field or column as readonly by using the simple 'readonly' attribute.

********************** readonly field ***********************************
$("input[title='Some Field Name']").attr('readonly','readonly');

This is Ok for input fields but jQuery doesn't support the readonly attribute for drop down lists so you may be tempted to use the disable attribute

*********************** disable a field **********************************
$("select[title='Some Field Name']").attr('disabled','disabled');

However disabling a select control means that when you click Ok the actual value is not posted in the form and consequently the select value is not passed into the SharePoint column

1 comment:

  1. A possible solution is to hide the drop down control (so it still exists and will get posted in the form) and use jQuery to grab the selected value from said hidden drop down list and display it in a textbox, which you can set to readonly, or in a styled div/span/whatever.

    ReplyDelete