jQuery中 Easy Dynamic Form Creator Tie.js

  • 源码大小:25.48KB
  • 所需积分:1积分
  • 源码编号:19JP-3353
  • 浏览次数:612次
  • 最后更新:2023年06月04日
  • 所属栏目:表单
本站默认解压密码:19jp.com 或 19jp_com

简介

Tie.js是一个简单而强大的表单生成器,它允许您从JSON数据动态生成HTML表单。因此,您可以在不必编写任何HTML代码的情况下,为您的网站或web应用程序提供动态表单。

该插件与最新的Bootstrap框架完全兼容,这意味着一旦生成,它将自动将Bootstrap的表单相关类添加到表单中的每个字段中。

参见:

  • 10个最佳表单生成器插件

如何使用它:

1.下载并加载文档中的Tie.js。

  1. <!-- Bootstrap is OPTIONAL -->
  2. <link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />
  3.  
  4. <!-- jQuery is Required -->
  5. <script src="/path/to/cdn/jquery.min.js"></script>
  6.  
  7. <!-- jQuery is Required -->
  8. <script src="/path/to/dist/tie.min.js"></script>

2.创建一个空类型元素。

  1. <form id="form"></form>

3.创建一个将绑定到表单的JS对象。

  1. var Signup = function() {
  2. var self = this;
  3. self.id = 0;
  4. self.username = '';
  5. self.password = '';
  6. self.email = '';
  7. };

4.初始化Tie.js插件。

  1. const signup = new Signup();
  2. const form = $('#form')
  3. form.TieJS({
  4. bindingSource: signup
  5. });

5.向表单中添加字段。

  1. const tiejs = form.data('tiejs').addFields([
  2. {
  3. type: "text",
  4. data: {
  5. label: "Username",
  6. name: "username",
  7. placeholder: "Username",
  8. attributes: ["autofocus"],
  9. required: true
  10. }
  11. },
  12. {
  13. type: "password",
  14. data: {
  15. label: "Password",
  16. name: "password",
  17. placeholder: "Password",
  18. required: true
  19. }
  20. },
  21. {
  22. type: "email",
  23. data: {
  24. label: "Email Address",
  25. name: "email",
  26. placeholder: "Email Address",
  27. }
  28. }
  29. ])
  30. .addBindings([{
  31. "username": "username",
  32. "password": "password",
  33. "email": "email"
  34. }
  35. ]);

6.可用的插件选项。

  1. form.TieJS({
  2. showRequiredAsterisk: true,
  3. requiredText: "Fields marked with an asterisk <span class='required-sign'>(*)</span> are required.",
  4. formName: null,
  5. bindingSource: {},
  6. onSubmit: function () {
  7. // do something
  8. }
  9. });

预览截图