From 9a650776e1d8b4daabe295729a544ec8bc484d0e Mon Sep 17 00:00:00 2001 From: Katy Powers Date: Thu, 18 Jun 2015 15:53:00 -0400 Subject: [PATCH 1/6] Added automatic generation of select options for stickit bindings. --- modules/FormView.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/FormView.js b/modules/FormView.js index 837acdcc..1cd73702 100644 --- a/modules/FormView.js +++ b/modules/FormView.js @@ -229,6 +229,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; }); }, @@ -356,7 +361,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 @@ -381,6 +386,29 @@ }; }, + /** + * @method _generateSelectOptions + * @param element {Element} The select element to generate options for + * @param opts {Object} Additional behavior options for the bindings + * @param [options.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'}; + + }, + /** * Creates the "when" bindings, and collates and invokes the "then" methods for all feedbacks * Finds all feedback zones that match the "to" field, and binds the "when" events to invoke the "then" method From 7baf251e08899802e2d9f1a8245fc0772c984b84 Mon Sep 17 00:00:00 2001 From: Katy Powers Date: Tue, 23 Jun 2015 10:33:39 -0400 Subject: [PATCH 2/6] Automatic generation of selectOptions for stickit bindings. --- modules/FormView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/FormView.js b/modules/FormView.js index 1cd73702..1f34c63a 100644 --- a/modules/FormView.js +++ b/modules/FormView.js @@ -390,11 +390,11 @@ * @method _generateSelectOptions * @param element {Element} The select element to generate options for * @param opts {Object} Additional behavior options for the bindings - * @param [options.modelFormat] {Object} The function called before setting model values + * @param [opts.modelFormat] {Object} The function called before setting model values * @private * @return {} */ - _generateSelectOptions: function(element, opts) { + __generateSelectOptions: function(element, opts) { var collection = [], options = $(element).children('option'); From 28ba9b6b93049f9854d288fcfde2405310361473 Mon Sep 17 00:00:00 2001 From: Katy Powers Date: Tue, 30 Jun 2015 09:16:33 -0400 Subject: [PATCH 3/6] Fixed problem in form view if statement --- modules/FormView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/FormView.js b/modules/FormView.js index 1f34c63a..4839d797 100644 --- a/modules/FormView.js +++ b/modules/FormView.js @@ -231,8 +231,8 @@ fieldBinding = self._generateModelFieldBinding(attr, options); //add select options - if $(element).is('select') { - fieldBinding.selectOptions = self._generateSelectOptions(element, options); + if ($(element).is('select')) { + fieldBinding.selectOptions = self.__generateSelectOptions(element, options); } self.bindings['[data-model="' + attr + '"]'] = fieldBinding; }); From c4ca7e1db4f010c9e1dc78c3ab83b7c8fed8ba2d Mon Sep 17 00:00:00 2001 From: Katy Powers Date: Tue, 30 Jun 2015 09:16:33 -0400 Subject: [PATCH 4/6] Fixed problem in form view if statement --- modules/FormView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/FormView.js b/modules/FormView.js index 1f34c63a..4839d797 100644 --- a/modules/FormView.js +++ b/modules/FormView.js @@ -231,8 +231,8 @@ fieldBinding = self._generateModelFieldBinding(attr, options); //add select options - if $(element).is('select') { - fieldBinding.selectOptions = self._generateSelectOptions(element, options); + if ($(element).is('select')) { + fieldBinding.selectOptions = self.__generateSelectOptions(element, options); } self.bindings['[data-model="' + attr + '"]'] = fieldBinding; }); From 0518dd7f80844618ce9e08e27ca17884a01e61a6 Mon Sep 17 00:00:00 2001 From: Katy Powers Date: Wed, 1 Jul 2015 18:18:54 -0400 Subject: [PATCH 5/6] Fixed problem with 'apply' in generate select options. --- modules/FormView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/FormView.js b/modules/FormView.js index 4839d797..7fd5afed 100644 --- a/modules/FormView.js +++ b/modules/FormView.js @@ -400,7 +400,7 @@ _.each(options, function(option) { collection.push({'label': $(option).text(), - 'value': opts.modelFormat ? opts.modelFormat.apply(this, $(option).val()) : $(option).val()}); + 'value': opts.modelFormat ? opts.modelFormat.apply(this, [$(option).val()]) : $(option).val()}); }); return {collection: collection, From 7990583323a46f6fc8b6f4405ed1057d2b74f46d Mon Sep 17 00:00:00 2001 From: Katy Powers Date: Mon, 6 Jul 2015 11:09:07 -0400 Subject: [PATCH 6/6] Fixed docstring for __generateSelectOptions. --- modules/FormView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/FormView.js b/modules/FormView.js index 7fd5afed..e3844c69 100644 --- a/modules/FormView.js +++ b/modules/FormView.js @@ -387,7 +387,7 @@ }, /** - * @method _generateSelectOptions + * @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