jqh 4 年之前
父節點
當前提交
8d39969db1
共有 2 個文件被更改,包括 19 次插入9 次删除
  1. 5 5
      resources/views/form/listfield.blade.php
  2. 14 4
      src/Form/Field/ListField.php

+ 5 - 5
resources/views/form/listfield.blade.php

@@ -18,7 +18,7 @@
 
         <table class="table table-hover">
 
-            <tbody class="list-{{$column}}-table">
+            <tbody class="list-{{$columnClass}}-table">
 
             @foreach(old("{$column}.values", ($value ?: [])) as $k => $v)
 
@@ -40,7 +40,7 @@
                     </td>
 
                     <td style="width: 85px;">
-                        <div class="{{$column}}-remove btn btn-white btn-sm pull-right">
+                        <div class="{{$columnClass}}-remove btn btn-white btn-sm pull-right">
                             <i class="feather icon-trash">&nbsp;</i>{{ __('admin.remove') }}
                         </div>
                     </td>
@@ -51,7 +51,7 @@
             <tr>
                 <td></td>
                 <td>
-                    <div class="{{ $column }}-add btn btn-success btn-sm pull-right">
+                    <div class="{{ $columnClass }}-add btn btn-success btn-sm pull-right">
                         <i class="feather icon-save"></i>&nbsp;{{ __('admin.new') }}
                     </div>
                 </td>
@@ -61,7 +61,7 @@
     </div>
 </div>
 
-<template class="{{$column}}-tpl">
+<template class="{{$columnClass}}-tpl">
     <tr>
         <td>
             <div class="form-group">
@@ -73,7 +73,7 @@
         </td>
 
         <td style="width: 85px;">
-            <div class="{{$column}}-remove btn btn-white btn-sm pull-right">
+            <div class="{{$columnClass}}-remove btn btn-white btn-sm pull-right">
                 <i class="feather icon-trash">&nbsp;</i>{{ __('admin.remove') }}
             </div>
         </td>

+ 14 - 4
src/Form/Field/ListField.php

@@ -145,19 +145,27 @@ class ListField extends Field
         $this->script = <<<JS
 (function () {
     var index = {$number};
-    $('.{$this->column}-add').on('click', function () {
-        var tpl = $('template.{$this->column}-tpl').html().replace('{key}', index);
-        $('tbody.list-{$this->column}-table').append(tpl);
+    $('.{$this->formatColumn()}-add').on('click', function () {
+        var tpl = $('template.{$this->formatColumn()}-tpl').html().replace('{key}', index);
+        $('tbody.list-{$this->formatColumn()}-table').append(tpl);
         
         index++;
     });
-    $('tbody').on('click', '.{$this->column}-remove', function () {
+    $('tbody').on('click', '.{$this->formatColumn()}-remove', function () {
         $(this).closest('tr').remove();
     });
 })();
 JS;
     }
 
+    /**
+     * @return mixed
+     */
+    protected function formatColumn()
+    {
+        return str_replace('.', '-', $this->column);
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -181,6 +189,8 @@ JS;
 
         Admin::style('td .form-group {margin-bottom: 0 !important;}');
 
+        $this->addVariables(['columnClass' => $this->formatColumn()]);
+
         return parent::render();
     }
 }