input-date.blade.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Date --}}
  7. <input id="{{ $id }}" name="{{ $name }}" data-target="#{{ $id }}" data-toggle="datetimepicker"
  8. {{ $attributes->merge(['class' => $makeItemClass()]) }}>
  9. @overwrite
  10. {{-- Add plugin initialization and configuration code --}}
  11. @push('js')
  12. <script>
  13. $(() => {
  14. let usrCfg = _AdminLTE_InputDate.parseCfg( @json($config) );
  15. $('#{{ $id }}').datetimepicker(usrCfg);
  16. // Add support to auto display the old submitted value or values in case
  17. // of validation errors.
  18. let value = @json($getOldValue($errorKey, $attributes->get('value')));
  19. $('#{{ $id }}').val(value || "");
  20. })
  21. </script>
  22. @endpush
  23. {{-- Register Javascript utility class for this component --}}
  24. @once
  25. @push('js')
  26. <script>
  27. class _AdminLTE_InputDate {
  28. /**
  29. * Parse the php plugin configuration and eval the javascript code.
  30. *
  31. * cfg: A json with the php side configuration.
  32. */
  33. static parseCfg(cfg)
  34. {
  35. for (const prop in cfg) {
  36. let v = cfg[prop];
  37. if (typeof v === 'string' && v.startsWith('js:')) {
  38. cfg[prop] = eval(v.slice(3));
  39. } else if (typeof v === 'object') {
  40. cfg[prop] = _AdminLTE_InputDate.parseCfg(v);
  41. }
  42. }
  43. return cfg;
  44. }
  45. }
  46. </script>
  47. @endpush
  48. @endonce