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

Created a delegate service for the select modal so we can reset, show programatically #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sn0opr
Copy link

@sn0opr sn0opr commented Jan 11, 2017

The problem that I faced is that I have a reset button on my form, but when I reset my select options model in my controller , the items stay selected in the select modal, because the isChecked object is not updated.

I used the same idea of ionic delegate service for their directives like the <ion-list> etc, this service will allow us to reset the selected options programatically or show the select modal, we may also add other methods in the future...

###Usage:
you should add handler-id attribute, an ID that we will use in our controller:

<button
                                    class="button button-block button-stable"
                                    modal-select=""
                                    ng-model="myModel.selectedItems"
                                    options="item"
                                    modal-title="Select an item"
                                    has-search="true"
                                    multiple="true"
                                    handler-id="myOptionsSelectId"
                            >
....

In our controller, we inject the modalSelectDelegate service, then we get our select modal handler by using the getHandler method:

var mySelectModalHandler = modalSelectDelegate.getHandler('myOptionsSelectId');

//Reset the values:
mySelectModalHandler.reset();
//Show the select modal:
mySelectModalHandler.show();

@bianchimro
Copy link
Member

hey @sn0opr , I like very much this delegate-service pattern used in ionic to manipulate directives scopes from outside, it's a great idea to apply it to the modal select directive.

The difference I see by looking at your code is that elsewhere in ionic delegate services, you do not need to specify a delegate-handle (this is often useful if you have only one instance of your directive in the current template or if you want to call the same method on all instances).
This could be a nice addition.

Anyway, your implementation looks good to me, let me give it a quick try (we don't have programmatic tests, can you help on #26 ?) and I'm going to merge your commit.

best regards
Mauro

@sn0opr sn0opr changed the title Created a delegate serice for the select modal so we can reset, show programatically Created a delegate service for the select modal so we can reset, show programatically Jan 13, 2017
@sn0opr
Copy link
Author

sn0opr commented Jan 13, 2017

@bianchimro thank you for your consideration, I've never made automatic tests for JS but this is a good occasion to learn how to make tests, but it may take some additional time for me.

@bianchimro
Copy link
Member

@sn0opr if you could help adding some automated test in the repo that would be great.

Testing this kind of project is quite difficult in my opinion as we have to test interface components (so we must describe what we expect to see) and we rely on existing services that we have to mock ($ionicModal in this case, but probably other ionic and angular components as well).

let's keep in touch about this if you want to give it a try!

@bianchimro
Copy link
Member

hi @sn0opr, seems like merging previous PRs creates a conflict with your code.
Can you please review your PR and remove the conflict?
regards

Mauro

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.

2 participants