input-slider.blade.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. @extends('adminlte::components.form.input-group-component')
  2. {{-- Set errors bag internallly --}}
  3. @php($setErrorsBag($errors ?? null))
  4. {{-- Set input group item section --}}
  5. @section('input_group_item')
  6. {{-- Input Slider --}}
  7. <input id="{{ $id }}" name="{{ $name }}"
  8. {{ $attributes->merge(['class' => $makeItemClass()]) }}>
  9. @overwrite
  10. {{-- Add plugin initialization and configuration code --}}
  11. @push('js')
  12. <script>
  13. $(() => {
  14. let usrCfg = @json($config);
  15. // Check for disabled attribute (alternative to data-slider-enable).
  16. @if($attributes->has('disabled'))
  17. usrCfg.enabled = false;
  18. @endif
  19. // Check for min, max and step attributes (alternatives to
  20. // data-slider-min, data-slider-max and data-slider-step).
  21. @if($attributes->has('min'))
  22. usrCfg.min = Number( @json($attributes['min']) );
  23. @endif
  24. @if($attributes->has('max'))
  25. usrCfg.max = Number( @json($attributes['max']) );
  26. @endif
  27. @if($attributes->has('step'))
  28. usrCfg.step = Number( @json($attributes['step']) );
  29. @endif
  30. // Check for value attribute (alternative to data-slider-value).
  31. // Also, add support to auto select the previous submitted value.
  32. @if($attributes->has('value') || ($errors->any() && $enableOldSupport))
  33. let value = @json($getOldValue($errorKey, $attributes['value']));
  34. if (value) {
  35. value = value.split(",").map(Number);
  36. usrCfg.value = value.length > 1 ? value : value[0];
  37. }
  38. @endif
  39. // Initialize the plugin.
  40. let slider = $('#{{ $id }}').bootstrapSlider(usrCfg);
  41. // Fix height conflict when orientation is vertical.
  42. let or = slider.bootstrapSlider('getAttribute', 'orientation');
  43. if (or == 'vertical') {
  44. $('#' + usrCfg.id).css('height', '210px');
  45. slider.bootstrapSlider('relayout');
  46. }
  47. })
  48. </script>
  49. @endpush
  50. {{-- Add CSS workarounds for the plugin --}}
  51. {{-- NOTE: this may change with newer plugin versions --}}
  52. @push('css')
  53. <style type="text/css">
  54. {{-- Setup plugin color --}}
  55. @isset($color)
  56. #{{ $config['id'] }} .slider-handle {
  57. background: {{ $color }};
  58. }
  59. #{{ $config['id'] }} .slider-selection {
  60. background: {{ $color }};
  61. opacity: 0.5;
  62. }
  63. #{{ $config['id'] }} .slider-tick.in-selection {
  64. background: {{ $color }};
  65. opacity: 0.9;
  66. }
  67. @endisset
  68. {{-- Set flex property when using addons slots --}}
  69. @if(isset($appendSlot) || isset($prependSlot))
  70. #{{ $config['id'] }} {
  71. flex: 1 1 0;
  72. align-self: center;
  73. @isset($appendSlot) margin-right: 5px; @endisset
  74. @isset($prependSlot) margin-left: 5px; @endisset
  75. }
  76. @endif
  77. </style>
  78. @endpush
  79. {{-- Setup custom invalid style --}}
  80. {{-- NOTE: this may change with newer plugin versions --}}
  81. @once
  82. @push('css')
  83. <style type="text/css">
  84. .adminlte-invalid-islgroup .slider-track,
  85. .adminlte-invalid-islgroup > .input-group-prepend > *,
  86. .adminlte-invalid-islgroup > .input-group-append > * {
  87. box-shadow: 0 .25rem 0.5rem rgba(255,0,0,.25);
  88. }
  89. .adminlte-invalid-islgroup .slider-vertical {
  90. margin-bottom: 1rem;
  91. }
  92. </style>
  93. @endpush
  94. @endonce