Guest User

Is there a jQuery jEditable Multi-select plugin

a guest
Nov 30th, 2011
1,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. $.editable.addInputType("multiselect", {
  2. element: function (settings, original) {
  3. var select = $('<select multiple="multiple" />');
  4.  
  5. if (settings.width != 'none') { select.width(settings.width); }
  6. if (settings.size) { select.attr('size', settings.size); }
  7.  
  8. $(this).append(select);
  9. return (select);
  10. },
  11. content: function (data, settings, original) {
  12. /* If it is string assume it is json. */
  13. if (String == data.constructor) {
  14. eval('var json = ' + data);
  15. } else {
  16. /* Otherwise assume it is a hash already. */
  17. var json = data;
  18. }
  19. for (var key in json) {
  20. if (!json.hasOwnProperty(key)) {
  21. continue;
  22. }
  23. if ('selected' == key) {
  24. continue;
  25. }
  26. var option = $('<option />').val(key).append(json[key]);
  27. $('select', this).append(option);
  28. }
  29.  
  30. if ($(this).val() == json['selected'] ||
  31. $(this).html() == $.trim(original.revert)) {
  32. $(this).attr('selected', 'selected');
  33. }
  34.  
  35. /* Loop option again to set selected. IE needed this... */
  36. $('select', this).children().each(function () {
  37. if (json.selected) {
  38. var option = $(this);
  39. $.each(json.selected, function (index, value) {
  40. if (option.val() == value) {
  41. option.attr('selected', 'selected');
  42. }
  43. });
  44. } else {
  45. if (original.revert.indexOf($(this).html()) != -1)
  46. $(this).attr('selected', 'selected');
  47. }
  48. });
  49. }
  50. });
  51.  
  52. $('.editable').editable('http://www.example.com/save.php', {
  53. data : " {'E':'Letter E','F':'Letter F','G':'Letter G', 'selected':'F'}",
  54. type : 'select',
  55. submit : 'OK'
  56. });
Advertisement
Add Comment
Please, Sign In to add comment