简体   繁体   English

如何向AlloyUI表单生成器添加自定义属性?

[英]How to add custom attributes to AlloyUI form builder?

I want to do something like this jsfiddle example , I need to put some custom attributes on left panel properties. 我想做类似此jsfiddle示例的操作 ,我需要在左侧面板属性上放置一些自定义属性。 Below I tried to make similarly but I can't drag the field 下面我尝试做类似的事情,但我不能拖动字段

YUI().use('aui-form-builder',function (Y) {

Y.MyFormCustom = Y.Component.create({ NAME: 'form-node', Y.MyFormCustom = Y.Component.create({NAME:'form-node',

      ATTRS: {
          type: {
              value: 'custom'
          },
          customAttr: {
              validator: Y.Lang.isString,
              value: 'A Custom default'
          }
      },

      EXTENDS: Y.FormBuilderFieldBase,

      prototype: {
          getPropertyModel: function () {
              var instance = this;

              var model = Y.FormBuilderFieldBase.superclass.getPropertyModel.apply(instance, arguments);

              model.push({
                  attributeName: 'customAttr',
                  name: 'Custom Attribute'
              });

              return model;
          }
      }
  });

  Y.FormBuilder.types['custom'] = Y.MyFormCustom;

  var availableFields = [
    {
    iconClass: 'form-builder-field-icon-button',
    label: 'Button',
    type: 'custom'
    }
  ];

  myform= new Y.FormBuilder({
      availableFields: availableFields,
      boundingBox: '#myHolder'
  }).render();

I don't know why the form is not appearing. 我不知道为什么表格没有出现。 Any help will be appreciated. 任何帮助将不胜感激。

Your example has been very helpful to me because I also needed to extend the Form Builder fields. 您的示例对我很有帮助,因为我还需要扩展“表单构建器”字段。

The fix to the above is simple. 上面的解决方法很简单。 Replace the line: 替换行:

Y.FormBuilder.types['custom'] = Y.MyFormCustom;

by 通过

Y.FormBuilderField.types['custom'] = Y.MyFormCustom;

This solution is inspired from the source code found in the Alloy UI API. 该解决方案的灵感来自Alloy UI API中的源代码。 See link: AlloyUI Form Builder 参见链接: AlloyUI Form Builder

Cheers 干杯

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

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