diff --git a/modules/FormView.js b/modules/FormView.js index 3556ef2b..41f33533 100644 --- a/modules/FormView.js +++ b/modules/FormView.js @@ -213,6 +213,11 @@ var attr = $(element).data('model'), options = self.__getFieldOptions(attr), fieldBinding = self.__generateModelFieldBinding(attr, options); + + //add select options + if ($(element).is('select')) { + fieldBinding.selectOptions = self.__generateSelectOptions(element, options); + } self.bindings['[data-model="' + attr + '"]'] = fieldBinding; }); }, @@ -230,7 +235,7 @@ /** * @method __generateModelFieldBinding * @param field {String} A specific model field - * @param options {Object} Additional heavior options for the bindings + * @param options {Object} Additional behavior options for the bindings * @param [options.modelFormat] {Object} The function called before setting model values * @param [options.viewFormat] {Object} The function called before setting view values * @private @@ -253,6 +258,28 @@ return options.viewFormat ? options.viewFormat.apply(this, params) : value; } }; + }, + + /** + * @method __generateSelectOptions + * @param element {Element} The select element to generate options for + * @param opts {Object} Additional behavior options for the bindings + * @param [opts.modelFormat] {Object} The function called before setting model values + * @private + * @return {} + */ + __generateSelectOptions: function(element, opts) { + var collection = [], + options = $(element).children('option'); + + _.each(options, function(option) { + collection.push({'label': $(option).text(), + 'value': opts.modelFormat ? opts.modelFormat.apply(this, [$(option).val()]) : $(option).val()}); + }); + + return {collection: collection, + labelPath: 'label', + valuePath: 'value'}; } });