Disable Shuttle Item Values


I recently had a requirement to disable some values in a Shuttle Item .  As the values to be disabled differed for different users I populated a hidden item with the values and then used JQuery to loop through the Option tag and disable them.  This worked great except for the ‘move all’ and ‘remove all’ features, which took a bit of extra thought.  Here’s what I ended up with:


 Function and Global Variable Declaration

function shuttleMove(pMove1,pMove2) {
  $("#P60_SHUTTLE_"+pMove2+" option").each(function () {
    if (!$(this).attr('disabled')) {
      $(this).appendTo('#P60_SHUTTLE_'+pMove1);
    }
  });
}

Execute when Page Loads

var valDis = ':' + $v(P60_HIDDEN) + ':';
$("#P60_SHUTTLE option").each(function () {
  var valThis = ':' +$(this).val() + ':';
  if (valDis.indexOf(valThis) > -1) {
    $(this).attr('disabled','disabled');
  }
});


$('#P60_SHUTTLE_MOVE_ALL').replaceWith('<a onclick="shuttleMove(\'RIGHT\',\'LEFT\');"><img alt="Move All" src="/i/htmldb/icons/shuttle_last.png"></a>');

$('#P60_SHUTTLE_REMOVE_ALL').replaceWith('<a onclick="shuttleMove(\'LEFT\',\'RIGHT\');"><img alt="Move All" src="/i/htmldb/icons/shuttle_first.png"></a>')

Comments