Skip to content
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

KnockoutJS data binding support #17

Merged
merged 1 commit into from
Feb 15, 2013
Merged

KnockoutJS data binding support #17

merged 1 commit into from
Feb 15, 2013

Conversation

Devristo
Copy link
Contributor

@Devristo Devristo commented Feb 8, 2013

Added KnockoutJS support by using a custom 'multiselect' binding handler.

The github diff is wrong. I only added the 'ko' related code at the top and changed the 'refresh' method and moved the creation of options into a function addOptions.

Example:

1. Define select input

Note the multiselect: true binding!

<select class="multiSelect" data-bind="multiselect: true, options: Options, selectedOptions: SelectedOptions, optionsValue: $data" multiple="multiple"></select>

2. Initialize Bootstrap-multiselect

$(".multiSelect").multiselect();

3 .Apply Knockout view model

As usual

Notes

It is important to do initialize multiselect before applying the view model, since the custom binding code will hook into the onChange method to update the binding.

Added KnockoutJS support by using a custom 'multiselect' binding handler.

Example:

1. Define select input
-------------------------
<select class="multiSelect" data-bind="multiselect: true,options: Options, selectedOptions: SelectedOptions, optionsValue: $data" multiple="multiple"></select>

1. Initialize Bootstrap-multiselect
-------------------------------------
$(".multiSelect").multiselect();

3 .Apply view model
@davidstutz
Copy link
Owner

Ok, cause I do not know anything about Knockout JS I can not help you with your problem, lucastschmidt.

I am just reviewing the pull request. One question: Why rebuilding the whole option list on the refresh method? Is this important for working with Knockout JS? Because I just started implementing a real rebuild functionality. I will merge your pull request, but will not test the plugin with Knockout JS! It would be nice if you could test it with Knockout JS after the next commit.

Thanks for your contribution!

davidstutz added a commit that referenced this pull request Feb 15, 2013
KnockoutJS data binding support.
@davidstutz davidstutz merged commit 6241c2e into davidstutz:master Feb 15, 2013
davidstutz added a commit that referenced this pull request Feb 16, 2013
Added a rebuild method suggested in Issue #19. Additionally added
documentation for Knockout JS - see Issue #17.
@Devristo
Copy link
Contributor Author

Complete rebuilding is important when using KnockoutJS since KnockoutJS is often used to bind an array to a as options. Currently your edit is not working, but the fix is easy. I have placed a comment on the specific line in your commit. Thanks for the awesome plugin!

@Devristo
Copy link
Contributor Author

Here is the change commit on my fork

Devristo/bootstrap-multiselect@b8adf3cb38912d623f6972d408e96fde867e2343

davidstutz added a commit that referenced this pull request Feb 25, 2013
@ronnyek
Copy link

ronnyek commented Feb 28, 2013

I dont know but this doesn't seem to work for me... I've got it bound and using the correct button text, but I only ever get items -1 items (eg, if I have 4 items in my observable array, I get 3 items in my list), and selecting any item will make it toggle all items selected or no items selected. if I click one of the 3 items, the button will say "4 items selected" even though only 3 display and 1 shows checked.
bad2
bad1

@ronnyek
Copy link

ronnyek commented Mar 1, 2013

Sorry... once I realized what was going on, I realized that because I was binding to a list of viewmodel I needed to ensure the optionsValue was being set. Little did I understand ahead of time, this option expect something like "id" a string representation of the value property.

@Devristo
Copy link
Contributor Author

Devristo commented Mar 1, 2013

Yeah, optionValue is required when data binding :)

davidstutz pushed a commit that referenced this pull request Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants