Browse Source

1.2.2 优化功能,修复bug

xaboy 7 years ago
parent
commit
3d505c7bd8
2 changed files with 24 additions and 3 deletions
  1. 18 0
      src/Form.php
  2. 6 3
      src/view/formScript.php

+ 18 - 0
src/Form.php

@@ -109,6 +109,8 @@ class Form
      */
     protected $action = '';
 
+    protected $id = '';
+
     /**
      * 提交方式
      * @var string
@@ -193,6 +195,22 @@ class Form
         return $this;
     }
 
+    /**
+     * @return string
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * @param string $id
+     */
+    public function setId($id)
+    {
+        $this->id = $id;
+    }
+
 
     /**
      * @return string

+ 6 - 3
src/view/formScript.php

@@ -9,10 +9,11 @@
             }
         });
         return rule;
-    }, vm = new Vue;
-    return function create(el, callback) {
+    }, vm = new Vue,name = 'formBuilderExec<?= empty($form->getId()) ? '' : '_'.$form->getId() ?>';
+
+    window[name] =  function create(el, callback) {
         if (!el) el = document.body;
-        return formCreate.create(getRule(), {
+        var $f = formCreate.create(getRule(), {
             el: el,
             form:<?=json_encode($form->getConfig('form'))?>,
             row:<?=json_encode($form->getConfig('row'))?>,
@@ -62,5 +63,7 @@
                 });
             }
         });
+        return $f;
     };
+    return window[name];
 }());