select.blade.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <script>
  2. @section('admin.select-ajax')
  3. @if(isset($ajax))
  4. configs = $.extend(configs, {
  5. ajax: {
  6. url: "{{ $ajax['url'] }}",
  7. dataType: 'json',
  8. delay: 250,
  9. data: function (params) {
  10. return {
  11. q: params.term,
  12. page: params.page
  13. };
  14. },
  15. processResults: function (data, params) {
  16. params.page = params.page || 1;
  17. return {
  18. results: $.map(data.data, function (d) {
  19. d.id = d.{{ $ajax['idField'] }};
  20. d.text = d.{{ $ajax['textField'] }};
  21. return d;
  22. }),
  23. pagination: {
  24. more: data.next_page_url
  25. }
  26. };
  27. },
  28. cache: true
  29. },
  30. escapeMarkup: function (markup) {
  31. return markup;
  32. }
  33. });
  34. @endif
  35. @overwrite
  36. </script>
  37. @if(isset($loads))
  38. {{--loads联动--}}
  39. <script once>
  40. var selector = '{!! $selector !!}';
  41. var fields = '{!! $loads['fields'] !!}'.split('^');
  42. var urls = '{!! $loads['urls'] !!}'.split('^');
  43. $(document).off('change', selector);
  44. $(document).on('change', selector, function () {
  45. Dcat.helpers.loadFields(this, {
  46. group: '{{ $loads['group'] ?? '.fields-group' }}',
  47. urls: urls,
  48. fields: fields,
  49. textField: "{{ $loads['textField'] }}",
  50. idField: "{{ $loads['idField'] }}",
  51. });
  52. });
  53. $(selector).trigger('change');
  54. </script>
  55. @endif
  56. <script once>
  57. // on first focus (bubbles up to document), open the menu
  58. $(document).off('focus', '.select2-selection.select2-selection--single')
  59. .on('focus', '.select2-selection.select2-selection--single', function (e) {
  60. $(this).closest(".select2-container").siblings('select:enabled').select2('open');
  61. });
  62. // steal focus during close - only capture once and stop propogation
  63. $(document).off('select2:closing', 'select.select2')
  64. .on('select2:closing', 'select.select2', function (e) {
  65. $(e.target).data("select2").$selection.one('focus focusin', function (e) {
  66. e.stopPropagation();
  67. });
  68. });
  69. </script>