2016-04-05 41 views
0

我想要做一些類似this jsfiddle example的事情,我需要在左面板屬性中添加一些自定義屬性。下面我試圖使類似,但我不能拖動字段如何將自定義屬性添加到AlloyUI表單生成器?

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

Y.MyFormCustom = Y.Component.create({ NAME: '形式節點',

 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(); 

我不「知道爲什麼形式沒有出現。任何幫助將不勝感激。

+0

它必須擴展您的自定義元素繼承的類。 在上面的代碼中,如果** EXTENDS:Y.FormBuilderFieldBase **,則在** availableFields中** _type_應該是一個輸入類型字段元素 – geo007us

回答

0

你舉的例子非常有幫助我,因爲我還需要延長的表單生成器領域。

的修復程序以上很簡單。 替換行:由

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

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

該溶液從合金UI API中發現的源代碼的啓發。 見鏈接: AlloyUI Form Builder

乾杯

相關問題