Bladeren bron

update widget form

jqh 5 jaren geleden
bovenliggende
commit
53f44bfed8
2 gewijzigde bestanden met toevoegingen van 33 en 4 verwijderingen
  1. 2 2
      resources/views/widgets/form.blade.php
  2. 31 2
      src/Widgets/Form.php

+ 2 - 2
resources/views/widgets/form.blade.php

@@ -1,4 +1,4 @@
-<form {!! $attributes !!}>
+{!! $start !!}
     <div class="box-body fields-group">
 
         @foreach($fields as $field)
@@ -31,4 +31,4 @@
         </div>
     </div>
     @endif
-</form>
+{!! $end !!}

+ 31 - 2
src/Widgets/Form.php

@@ -376,18 +376,39 @@ class Form implements Renderable
      */
     protected function getVariables()
     {
+        $this->setHtmlAttribute('id', $this->getFormId());
+
         foreach ($this->fields as $field) {
             $field->fill($this->data->toArray());
         }
 
         return [
+            'start'      => $this->open(),
+            'end'        => $this->close(),
             'fields'     => $this->fields,
-            'attributes' => $this->formatHtmlAttributes(),
             'method'     => $this->getHtmlAttribute('method'),
             'buttons'    => $this->buttons,
         ];
     }
 
+    /**
+     * @return string
+     */
+    protected function open()
+    {
+        return <<<HTML
+<form {$this->formatHtmlAttributes()}>
+HTML;
+    }
+
+    /**
+     * @return string
+     */
+    protected function close()
+    {
+        return '</form>';
+    }
+
     /**
      * Determine if form fields has files.
      *
@@ -477,10 +498,18 @@ var f = $('#{$this->getFormId()}');
 
 f.find('[type="submit"]').click(function () {
     var t = $(this);
-    t.button('loading');
     
     LA.Form({
         \$form: f,
+         before: function () {
+            f.validator('validate');
+    
+            if (f.find('.has-error').length > 0) {
+                return false;
+            }
+            
+            t.button('loading');
+        },
         after: function () {
             t.button('reset');
         }