jqh 4 years ago
parent
commit
8a5236b887
4 changed files with 25 additions and 26 deletions
  1. 0 15
      resources/views/widgets/form.blade.php
  2. 2 4
      src/Form/Builder.php
  3. 1 1
      src/Grid.php
  4. 22 6
      src/Widgets/Form.php

+ 0 - 15
resources/views/widgets/form.blade.php

@@ -33,18 +33,3 @@
 
     {!! $footer !!}
 {!! $end !!}
-
-@if(! empty($ajax))
-<script>
-    $('#{{ $elementId }}').form({
-        validate: true,
-        confirm: {!! admin_javascript_json($confirm) !!},
-        success: function (data) {
-            {!! $savedScript !!}
-        },
-        error: function (response) {
-            {!! $errorScript !!}
-        }
-    });
-</script>
-@endif

+ 2 - 4
src/Form/Builder.php

@@ -808,12 +808,10 @@ EOF;
     protected function doWrap(Renderable $view)
     {
         if ($wrapper = $this->wrapper) {
-            return Admin::resolveHtml($wrapper($view))['html'];
+            return Helper::render($wrapper($view));
         }
 
-        $html = Admin::resolveHtml($view->render())['html'];
-
-        return "<div class='card'>{$html}</div>";
+        return "<div class='card'>{$view->render()}</div>";
     }
 
     /**

+ 1 - 1
src/Grid.php

@@ -897,7 +897,7 @@ HTML;
             return $view->render();
         }
 
-        return $wrapper($view);
+        return Helper::render($wrapper($view));
     }
 
     /**

+ 22 - 6
src/Widgets/Form.php

@@ -855,11 +855,7 @@ HTML;
         $this->prepareHandler();
 
         if ($this->allowAjaxSubmit()) {
-            $this->addVariables([
-                'confirm'     => $this->confirm,
-                'savedScript' => $this->savedScript(),
-                'errorScript' => $this->errorScript(),
-            ]);
+            $this->addAjaxScript();
         }
 
         $tabObj = $this->getTab();
@@ -872,7 +868,27 @@ HTML;
             'tabObj' => $tabObj,
         ]);
 
-        return Admin::view($this->view, $this->variables());
+        return view($this->view, $this->variables())->render();
+    }
+
+    protected function addAjaxScript()
+    {
+        $confirm = admin_javascript_json($this->confirm);
+
+        Admin::script(
+            <<<JS
+$('#{$this->getElementId()}').form({
+    validate: true,
+    confirm: {$confirm},
+    success: function (data) {
+        {$this->savedScript()}
+    },
+    error: function (response) {
+        {$this->errorScript()}
+    }
+});
+JS
+        );
     }
 
     /**