form-samples.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var FormSamples = function () {
  2. return {
  3. //main function to initiate the module
  4. init: function () {
  5. // use select2 dropdown instead of chosen as select2 works fine with bootstrap on responsive layouts.
  6. $('.select2_category').select2({
  7. placeholder: "Select an option",
  8. allowClear: true
  9. });
  10. $('.select2_sample1').select2({
  11. placeholder: "Select a State",
  12. allowClear: true
  13. });
  14. $(".select2_sample2").select2({
  15. placeholder: "Type to select an option",
  16. allowClear: true,
  17. minimumInputLength: 1,
  18. query: function (query) {
  19. var data = {
  20. results: []
  21. }, i, j, s;
  22. for (i = 1; i < 5; i++) {
  23. s = "";
  24. for (j = 0; j < i; j++) {
  25. s = s + query.term;
  26. }
  27. data.results.push({
  28. id: query.term + i,
  29. text: s
  30. });
  31. }
  32. query.callback(data);
  33. }
  34. });
  35. $(".select2_sample3").select2({
  36. tags: ["red", "green", "blue", "yellow", "pink"]
  37. });
  38. }
  39. };
  40. }();