简体   繁体   English

如何将自定义字段添加到Jquery表单生成器

[英]How to add custom field to Jquery Form Builder

there, 那里,

I'm working with Jquery Form Builder ( https://formbuilder.online/ ) and I got to the task: add custom field to the form builder. 我正在使用Jquery Form Builder( https://formbuilder.online/ ),我完成了任务:将自定义字段添加到表单构建器。

I want to do it without change the core of this jquery plugin. 我想这样做而不改变这个jquery插件的核心。 I already found that I can add it to the function "fieldRender", between other changes. 我已经发现我可以在其他更改之间将它添加到函数“fieldRender”。

Doing this I would lose updates of this project, and this custom fields are too specific to offer to the project itself. 这样做我将丢失此项目的更新,并且此自定义字段太具体,无法提供给项目本身。

I'm already looking for some time and didn't find yet: does anyone knows if there is a way to add custom fields with a sort of extension strategy, so I could build custom fields without change the core code everytime? 我已经找了一段时间但还没找到:有没有人知道是否有办法用一种扩展策略添加自定义字段,所以我可以构建自定义字段而不必每次更改核心代码?

Thanks, 谢谢,

Support for custom elements was officially added in v2.1 http://formbuilder.readthedocs.io/en/latest/formBuilder/options/templates/ v2.1正式添加了对自定义元素的支持http://formbuilder.readthedocs.io/en/latest/formBuilder/options/templates/

You add 2 options to the editor. 您向编辑器添加了2个选项。 For example if you want a Star Rating input 例如,如果您想要星级评分输入

var fields = [{
  label: 'Star Rating',
  attrs: {
    type: 'starRating'
  },
  icon: '🌟'
}];
var templates = {
  starRating: function(fieldData) {
    return {
      field: '<span id="'+fieldData.name+'">',
      onRender: function() {
        $(document.getElementById(fieldData.name)).rateYo({rating: 3.6});
      }
    };
  }
};
var options = {
  fields: fields,
  options: options
};
$('#fb-editor').formBuilder(options);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM