listfield.blade.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <style>
  2. td .form-group {margin-bottom: 0 !important;}
  3. </style>
  4. <div class="{{$viewClass['form-group']}} {{$class}}">
  5. <label class="{{$viewClass['label']}} control-label">{{$label}}</label>
  6. <div class="{{$viewClass['field']}}">
  7. <div class="help-block with-errors"></div>
  8. <span name="{{$name}}"></span>
  9. <input name="{{ $name }}[values][{{ Dcat\Admin\Form\Field\ListField::DEFAULT_FLAG_NAME }}]" type="hidden" />
  10. <table class="table table-hover">
  11. <tbody class="list-table">
  12. @foreach(($value ?: []) as $k => $v)
  13. <tr>
  14. <td>
  15. <div class="form-group">
  16. <div class="col-sm-12">
  17. <input name="{{ $name }}[values][{{ (int) $k }}]" value="{{ $v }}" class="form-control" />
  18. <div class="help-block with-errors"></div>
  19. </div>
  20. </div>
  21. </td>
  22. <td style="width: 85px;">
  23. <div class="{{$class}}-remove list-remove btn btn-white btn-sm pull-right">
  24. <i class="feather icon-trash">&nbsp;</i>
  25. </div>
  26. </td>
  27. </tr>
  28. @endforeach
  29. </tbody>
  30. <tfoot>
  31. <tr>
  32. <td></td>
  33. <td>
  34. <div class="list-add btn btn-primary btn-outline btn-sm pull-right">
  35. <i class="feather icon-save"></i>&nbsp;{{ __('admin.new') }}
  36. </div>
  37. </td>
  38. </tr>
  39. </tfoot>
  40. </table>
  41. </div>
  42. <template>
  43. <tr>
  44. <td>
  45. <div class="form-group">
  46. <div class="col-sm-12">
  47. <input name="{{ $name }}[values][{key}]" class="form-control" />
  48. <div class="help-block with-errors"></div>
  49. </div>
  50. </div>
  51. </td>
  52. <td style="width: 85px;">
  53. <div class="list-remove btn btn-white btn-sm pull-right">
  54. <i class="feather icon-trash">&nbsp;</i>
  55. </div>
  56. </td>
  57. </tr>
  58. </template>
  59. </div>
  60. <script init="{!! $selector !!}">
  61. var index = {{ $count }};
  62. $this.find('.list-add').on('click', function () {
  63. var tpl = $this.find('template').html().replace('{key}', index);
  64. $this.find('tbody.list-table').append(tpl);
  65. index++;
  66. });
  67. $this.find('tbody.list-table').on('click', '.list-remove', function () {
  68. $(this).closest('tr').remove();
  69. });
  70. </script>