jqh 4 anos atrás
pai
commit
e4b878255c
2 arquivos alterados com 47 adições e 33 exclusões
  1. 6 6
      src/Widgets/ApexCharts/Chart.php
  2. 41 27
      src/Widgets/Form.php

+ 6 - 6
src/Widgets/ApexCharts/Chart.php

@@ -32,14 +32,14 @@ class Chart extends Widget
         'extend' => 'return options',
     ];
 
-    public function __construct($containerSelector = null, $options = [])
+    public function __construct($selector = null, $options = [])
     {
-        if ($containerSelector && ! is_string($containerSelector)) {
-            $options = $containerSelector;
-            $containerSelector = null;
+        if ($selector && ! is_string($selector)) {
+            $options = $selector;
+            $selector = null;
         }
 
-        $this->selector($containerSelector);
+        $this->selector($selector);
 
         $this->options($options);
     }
@@ -246,7 +246,7 @@ JS;
     public function addScript()
     {
         if (! $this->allowBuildRequest()) {
-            return $this->buildDefaultScript();
+            return $this->script = $this->buildDefaultScript();
         }
 
         $this->fetched(

+ 41 - 27
src/Widgets/Form.php

@@ -100,6 +100,7 @@ class Form implements Renderable
 
     const REQUEST_NAME = '_form_';
     const CURRENT_URL_NAME = '_current_';
+    const LAZY_PAYLOAD_NAME = '_payload_';
 
     /**
      * @var string
@@ -189,6 +190,8 @@ class Form implements Renderable
         $this->initFormAttributes();
 
         $this->initCurrentUrl();
+
+        $this->initPayload();
     }
 
     /**
@@ -220,6 +223,13 @@ class Form implements Renderable
         }
     }
 
+    protected function initPayload()
+    {
+        if ($payload = \request(static::LAZY_PAYLOAD_NAME)) {
+            $this->payload(json_decode($payload, true) ?? []);
+        }
+    }
+
     /**
      * Action uri of the form.
      *
@@ -663,33 +673,6 @@ HTML;
         return $this->defaultSetCurrentUrl($url);
     }
 
-    /**
-     * Generate a Field object and add to form builder if Field exists.
-     *
-     * @param string $method
-     * @param array  $arguments
-     *
-     * @return Field|null
-     */
-    public function __call($method, $arguments)
-    {
-        if ($className = static::findFieldClass($method)) {
-            $name = Arr::get($arguments, 0, '');
-
-            $element = new $className($name, array_slice($arguments, 1));
-
-            $this->pushField($element);
-
-            return $element;
-        }
-
-        if (static::hasMacro($method)) {
-            return $this->macroCall($method, $arguments);
-        }
-
-        throw new \BadMethodCallException("Field [{$method}] does not exist.");
-    }
-
     /**
      * Disable submit with ajax.
      *
@@ -828,6 +811,10 @@ JS
             $this->action(route(admin_api_route('form')));
             $this->hidden(static::REQUEST_NAME)->default(get_called_class());
             $this->hidden(static::CURRENT_URL_NAME)->default($this->getCurrentUrl());
+
+            if (! empty($this->payload) && is_array($this->payload)) {
+                $this->hidden(static::LAZY_PAYLOAD_NAME)->default(json_encode($this->payload));
+            }
         }
     }
 
@@ -857,6 +844,33 @@ JS
         return view($this->view, $this->variables())->render();
     }
 
+    /**
+     * Generate a Field object and add to form builder if Field exists.
+     *
+     * @param string $method
+     * @param array  $arguments
+     *
+     * @return Field|null
+     */
+    public function __call($method, $arguments)
+    {
+        if ($className = static::findFieldClass($method)) {
+            $name = Arr::get($arguments, 0, '');
+
+            $element = new $className($name, array_slice($arguments, 1));
+
+            $this->pushField($element);
+
+            return $element;
+        }
+
+        if (static::hasMacro($method)) {
+            return $this->macroCall($method, $arguments);
+        }
+
+        throw new \BadMethodCallException("Field [{$method}] does not exist.");
+    }
+
     /**
      * Output as string.
      *