-
Notifications
You must be signed in to change notification settings - Fork 20
Added automatic generation of select options for stickit bindings. #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ccpowers
wants to merge
8
commits into
vecnatechnologies:master
Choose a base branch
from
ccpowers:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a65077
Added automatic generation of select options for stickit bindings.
katypowers 7baf251
Automatic generation of selectOptions for stickit bindings.
katypowers 28ba9b6
Fixed problem in form view if statement
katypowers c4ca7e1
Fixed problem in form view if statement
katypowers 0518dd7
Fixed problem with 'apply' in generate select options.
katypowers 48f46a5
Merge branch 'master' of https://github.com/ccpowers/backbone-torso
katypowers 7990583
Fixed docstring for __generateSelectOptions.
katypowers 53ac0d8
Merge remote-tracking branch 'upstream/master'
katypowers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 {<Stickit select options hash>} | ||
| */ | ||
| __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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an issue to Torso that explains the bug and reference the issue in this commit message.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. See #84. |
||
| labelPath: 'label', | ||
| valuePath: 'value'}; | ||
| } | ||
| }); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last question. This all looks good, but I'm a little worried about blowing away your select options if they have different classes/attributes that you had added before. Will you lose classes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested this- you will lose classes on the select options. You won't lose data on the actual select though. There might be a clever way to get around this with the 'classes' bindings available in stickit - I will think about it some more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There doesn't seem to be a way to keep your classes while binding select options using selectOptions - any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ccpowers, I think you should merge this. Though, let's create an enhancement to keep classes on two-way bound select options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ccpowers, do you want to keep working on this or should I take over?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kentmw I'm happy to finish it but i'm about to leave the country for a month so if you want it done before October, you should probably take over...just let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can wait until you get back, that will be fine. If we need it before you return, we'll create a new PR. Have fun!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ccpowers, are you back? Any interest in picking this back up? We're pretty close to finishing.