xeditable-demo.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. $(function(){
  2. //Uncomment the line and switch modes
  3. //$.fn.editable.defaults.mode = 'inline';
  4. //editables
  5. $('#username').editable({
  6. type: 'text',
  7. pk: 1,
  8. name: 'username',
  9. title: 'Enter username'
  10. });
  11. $('#firstname').editable({
  12. validate: function(value) {
  13. if($.trim(value) == '') return 'This field is required';
  14. }
  15. });
  16. $('#sex').editable({
  17. prepend: "not selected",
  18. source: [
  19. {value: 1, text: 'Male'},
  20. {value: 2, text: 'Female'}
  21. ],
  22. display: function(value, sourceData) {
  23. var colors = {"": "gray", 1: "green", 2: "blue"},
  24. elem = $.grep(sourceData, function(o){return o.value == value;});
  25. if(elem.length) {
  26. $(this).text(elem[0].text).css("color", colors[value]);
  27. } else {
  28. $(this).empty();
  29. }
  30. }
  31. });
  32. $('#status').editable();
  33. $('#group').editable({
  34. showbuttons: false
  35. });
  36. $('#dob').editable();
  37. $('#comments').editable({
  38. showbuttons: 'bottom'
  39. });
  40. //inline
  41. $('#inline-username').editable({
  42. type: 'text',
  43. pk: 1,
  44. name: 'username',
  45. title: 'Enter username',
  46. mode: 'inline'
  47. });
  48. $('#inline-firstname').editable({
  49. validate: function(value) {
  50. if($.trim(value) == '') return 'This field is required';
  51. },
  52. mode: 'inline'
  53. });
  54. $('#inline-sex').editable({
  55. prepend: "not selected",
  56. mode: 'inline',
  57. source: [
  58. {value: 1, text: 'Male'},
  59. {value: 2, text: 'Female'}
  60. ],
  61. display: function(value, sourceData) {
  62. var colors = {"": "gray", 1: "green", 2: "blue"},
  63. elem = $.grep(sourceData, function(o){return o.value == value;});
  64. if(elem.length) {
  65. $(this).text(elem[0].text).css("color", colors[value]);
  66. } else {
  67. $(this).empty();
  68. }
  69. }
  70. });
  71. $('#inline-status').editable({mode: 'inline'});
  72. $('#inline-group').editable({
  73. showbuttons: false,
  74. mode: 'inline'
  75. });
  76. $('#inline-dob').editable({mode: 'inline'});
  77. $('#inline-comments').editable({
  78. showbuttons: 'bottom',
  79. mode: 'inline'
  80. });
  81. });