Skip to main content
Blindly update based on a comment
Source Link
eirikb
  • 7.4k
  • 5
  • 36
  • 67

Clear it? Would it be good enough to just move the items back to where they came from, by selecting them on the right side and clicking the button.

Something like this:

$('.ms-formbody').filter(function() {
  return $(this).html().match(/spfieldlookup/i) && $(this).find('select').size() >= 1;
}).each(function() {
  var $btn = $('<button>').text('Clear');
  var $select = $(this).find('select:last');
  var $remove = $(this).find('button:last');
  $btn.click(function() {
    $select.val($select.find('option').map(function() {
      return $(this).val();
    }).toArray());
    $remove.removeAttr('disabled').click();
    return false;
  });
  $(this).prepend($btn);
});​

Clear it? Would it be good enough to just move the items back to where they came from, by selecting them on the right side and clicking the button.

Something like this:

$('.ms-formbody').filter(function() {
  return $(this).html().match(/spfieldlookup/i) && $(this).find('select').size() >= 1;
}).each(function() {
  var $btn = $('<button>').text('Clear');
  var $select = $(this).find('select:last');
  var $remove = $(this).find('button:last');
  $btn.click(function() {
    $select.val($select.find('option').map(function() {
      return $(this).val();
    }).toArray());
    $remove.click();
    return false;
  });
  $(this).prepend($btn);
});​

Clear it? Would it be good enough to just move the items back to where they came from, by selecting them on the right side and clicking the button.

Something like this:

$('.ms-formbody').filter(function() {
  return $(this).html().match(/spfieldlookup/i) && $(this).find('select').size() >= 1;
}).each(function() {
  var $btn = $('<button>').text('Clear');
  var $select = $(this).find('select:last');
  var $remove = $(this).find('button:last');
  $btn.click(function() {
    $select.val($select.find('option').map(function() {
      return $(this).val();
    }).toArray());
    $remove.removeAttr('disabled').click();
    return false;
  });
  $(this).prepend($btn);
});​
Source Link
eirikb
  • 7.4k
  • 5
  • 36
  • 67

Clear it? Would it be good enough to just move the items back to where they came from, by selecting them on the right side and clicking the button.

Something like this:

$('.ms-formbody').filter(function() {
  return $(this).html().match(/spfieldlookup/i) && $(this).find('select').size() >= 1;
}).each(function() {
  var $btn = $('<button>').text('Clear');
  var $select = $(this).find('select:last');
  var $remove = $(this).find('button:last');
  $btn.click(function() {
    $select.val($select.find('option').map(function() {
      return $(this).val();
    }).toArray());
    $remove.click();
    return false;
  });
  $(this).prepend($btn);
});​