是否可以在 jQuery FormBuilder 中预设新选择的类型?

Is it possible to preset the type of a new selection in the jQuery FormBuilder?

我使用 Kevin Chappell 的 FormBuilder

https://formbuilder.online/docs/

可以为 'text' 字段定义多种类型。我已经集成了新控件 'time'。我现在想要如果单击这个新控件,'time' 应该在 'Type' 字段中预设。

我该如何调整?

PS: 代码示例不在运行这里,只在本地(sessionStorage主题)

jQuery(function($) {
  var fbTemplate = document.getElementById('fb-editor');
  var options = {
    fields : [{
        label: 'Time',
        attrs: {
            type: 'text'
        },
        icon: ''
    }],
    subtypes: {
      text: ['datetime-local','time']
    },
    disabledSubtypes: {
        text: ['password','email','color','tel'],
    }
  };
  $(fbTemplate).formBuilder(options);
});
body {
  background: lightgrey;
  font-family: sans-serif;
}
<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>CodePen - formBuilder: Options -&gt; subtypes</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>
<!-- partial:index.partial.html -->
<div id="fb-editor"></div>
<!-- partial -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
<script src='https://formbuilder.online/assets/js/form-builder.min.js'></script><script  src="./script.js"></script>

</body>
</html>

我没有发现,但我选择了不同的道路。 :-)

field 定义中输入 time 类型的新元素。 还定义了一个新的 subtype time

然后在controls register中添加time

jQuery(function($) {
  var fbTemplate = document.getElementById('fb-editor');
  var options = {
    fields : [{
      label: 'Time',
      attrs: {
        type: 'time'
      },
      icon: ''
    }],
    subtypes: {
      time: ['time']
    }
  };
  $(fbTemplate).formBuilder(options);
});

// src/js/control/text.js
// register this control for the following types & text subtypes
control.register(['text', 'file', 'date', 'number', 'time'], controlText)
control.register(['text', 'password', 'email', 'color', 'tel'], controlText, 'text')
body {
  background: lightgrey;
  font-family: sans-serif;
}
<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>formBuilder</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>

<div id="fb-editor"></div>

<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
<script src='https://formbuilder.online/assets/js/form-builder.min.js'></script>
<script  src="./script.js"></script>

</body>
</html>