瀏覽代碼

支持自定义ID

jqh 4 年之前
父節點
當前提交
7d2b464d74
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. 3 2
      src/Form/Tab.php

+ 3 - 2
src/Form/Tab.php

@@ -52,17 +52,18 @@ class Tab
      * @param string   $title
      * @param \Closure $content
      * @param bool     $active
+     * @param string   $id
      *
      * @return $this
      */
-    public function append($title, \Closure $content, $active = false)
+    public function append($title, \Closure $content, bool $active = false, ?string $id = null)
     {
         call_user_func($content, $this->form);
 
         $fields = $this->collectFields();
         $layout = $this->collectColumnLayout();
 
-        $id = 'tab-form-'.($this->tabs->count() + 1).'-'.mt_rand(0, 9999);
+        $id = $id ?: ('tab-form-'.($this->tabs->count() + 1).'-'.mt_rand(0, 9999));
 
         $this->tabs->push(compact('id', 'title', 'fields', 'active', 'layout'));