I finally found a select menu plugin smart enough to work in IE comparability mode and also allows me to fire an event before the menu options are displaced. This awesome plugin is called jQuery Selectric.
I need to fire an event before the options are displayed and I want to make an ajax request which tells me which option I should enable/disable.
I was able to make the ajax request before the menu opens. but I am having hard time trying to disable the options. The options are always enabled even after I disable them.
I tried to use the $('select').selectric('refresh');
on ajax sucess but his cause a problem that the menu will never get a chance to open because just before it open the ajax request will close it again.
How can I disable options on the fly?
Here is what I have done
$('#MasterWrapUps').selectric();
$('#MasterWrapUps').on('selectric-before-open', function (e) {
var status = "noattempt";
$.ajax({
type: "GET",
url: "/getStatus",
dataType: "json",
cache: false,
success: function (data) {
if ( data && ! $.isEmptyObject(data) ) {
status = data.status;
}
attrWrapUpMenu(status);
}
});
});
function attrWrapUpMenu(status)
{
$('.dispositionMenuOption').each(function (index, element) {
var option = $(element);
if ( customIsAllowed(status, option) ) {
option.attr("disabled", false);
} else {
if( option.attr('selected') ) {
//At this point we know the option that is select can't be used, select the default value
$('#MasterWrapUps').val('0')
}
option.attr("disabled", true);
}
});
}