define(['dojo/_base/declare','dojo/_base/array','dojo/_base/lang', 'dojo/dom-construct','dijit/registry','dijit/_WidgetBase', 'dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin','dijit/_Container', 'dojo/text!./templates/MultipleChoiceWidget.html', 'dijit/form/RadioButton','dijit/form/CheckBox','dijit/form/TextBox','dijit/form/Button' ], function(declare,array,lang,domConstruct,registry,_WidgetBase,_TemplatedMixin, _WidgetsInTemplateMixin,_Container, templateString,RadioButton,CheckBox,TextBox,Button){ return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{ templateString: templateString, multiple: true, baseClass: 'rftMultipleChoiceWidget', allowMultiple: false, name: '', value: null, _widgetCache: null, constuctor: function() { this.inherited(arguments); this.value = []; this._widgetCache = {}; }, _setValueAttr: function(value) { this.reset(); this.value = value; array.forEach(this.value,lang.hitch(this,function(val){ this._addRow(val); })); }, _getValueAttr: function() { var value = []; registry.findWidgets(this.domNode).forEach(function(w){ if ( w.isInstanceOf(TextBox) ) { value.push(w.get('value')); } }); this.value = value; return value; }, reset: function() { this._removeWidgetsBelowNode(this.rows); domConstruct.empty(this.rows); }, _onAddRow: function() { this._addRow(); }, _addRow: function(value,tagRow,pos) { var row = domConstruct.create('div',{className:'row'}); if ( this.allowMultiple ) { new CheckBox({ name:this.name, className:'rowBox', disabled: this.mode === 'edit' }).placeAt(row); } else { new RadioButton({ name:this.name, className:'rowBox', disabled: this.mode === 'edit' }).placeAt(row); } new TextBox({ name:this.name, value:value || '', className:'rowText' }).placeAt(row); new Button({ label:'-', className:'rowBtn', onClick:lang.hitch(this,'_removeNodeWithWidgets',row) }).placeAt(row); new Button({ label:'+', className:'rowBtn', onClick:lang.hitch(this,'_addRow','',row,'before') }).placeAt(row); domConstruct.place(row,tagRow || this.rows,pos||'last'); }, _removeNodeWithWidgets: function(node) { this._removeWidgetsBelowNode(node); domConstruct.destroy(node); }, _removeWidgetsBelowNode: function(node) { registry.findWidgets(node).forEach(function(w){ w.destroyRecursive(); }); }, _onRowChange: function(/*row*/) {} }); });