如何在 jQuery FormBuilder 中添加新的通用属性

问题描述

我正在使用 jQuery FormBuilder (https://formbuilder.online/),我需要一个自定义属性作为每种类型的复选框。因此,无论是文本区域、文本输入、复选框还是类似的,我总是想添加相同的复选框作为新属性

我的选项如下:

options = {
    scrollToFieldOnAdd: false,disableFields: ['button','file','hidden'],disabledAttrs: ['access'],// Add custom checkBox property to the form
    typeUserAttrs: {
        text: {
            showInGroupDesc: {
                type: 'checkBox',label: 'Show in Group Desc.?'
            }
        }
    }
}

它使用了 typeUserAttrs,不幸的是,我必须准确指定要将新属性 showInGroupDesc 添加到的字段类型。

我不想在 typeUserAttrs 中为每种类型复制/粘贴此元素 - 是否有通配符设置?

解决方法

通过在将对象 userAttrs 传递给 newAttributes 之前使用新属性 typeUserAttrs 初始化它,我自己找到了一个解决方案:

// New attribute for specified fields 'fields' below
var newAttributes = {
            showInGroupDesc: {
                type: 'checkbox',label: 'Show in Group Desc.?'
            }
        };
var userAttrs = {};
const fields = ["autocomplete","checkbox-group","date","number","radio-group","select","text","textarea"];
fields.forEach(function (item,index) {
    userAttrs[item] = newAttributes;
});

// Initialise the form builder
options = {
    // ... All your options here ...
    typeUserAttrs: userAttrs
  };

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...