lordfriend / nya-bootstrap-select

An AngularJS select replacement which build select like dropdown component with collection and ng-model support
http://nya.io/nya-bootstrap-select/
MIT License
178 stars 81 forks source link

Single selection drop-down unable to reset the values in nya bootstrap select in angular 1.5 #182

Open shivaprakashboss opened 6 years ago

shivaprakashboss commented 6 years ago

I am using nya bootstrap select for dropdowns when I click reset to bring back the values from the DB values are not resetting on UI .The old value getting retained on screen even though in controller the values are fetched from DB. How to tackle this ? Please help we badly need this

shivaprakashboss commented 6 years ago

I even tried with setting the variable to undefined or "" or null or {} but no luck this happens for single selection but multiple it is working fine.

shivaprakashboss commented 6 years ago

On clicking the reset button ,In the controller ,scope variable have the new values that is not reflecting on the UI where it has previous selected values.this is not happening on first time loading of page where I fetch the same data from database.

lordfriend commented 6 years ago

No built-in reset (unselect) in single select mode. You have to reset your model to undefined or null.

shivaprakashboss commented 6 years ago

I have reset the model to undefined as well as null but there is no expected behaviour. Say $scope.users={} or $scope.users=null I didn't see the value getting reset. Please help

shivaprakashboss commented 6 years ago

Even if I reset to some other value also it is not resetting to that value let me know what I am missing.

MrWook commented 6 years ago

works fine for me

shivaprakashboss commented 6 years ago

could you please share the example how you do it and share the nya.bootstrap.select.js file. today morning i checked the reset with latest nya.bootstrap.select.js file. reset is working fine when we change the value in the controller but after that if i change the items in the dropdown ,model not getting updated.Please help

MrWook commented 6 years ago

Click on my text in the previous comment, it is a link, it glows blue.

But to reset the model to undefined and change the present data is a different thing. Try to add deep-watch="true" on the same element as "nya-bs-option"

shivaprakashboss commented 6 years ago

i have added deep-watch and sorry angular version is 1.3 not 1.5 please help

shivaprakashboss commented 6 years ago

is the version mismatch makes this behave indifferent ?

shivaprakashboss commented 6 years ago

i have gone through your link and it is working as expected

MrWook commented 6 years ago

I added a complete data set change and a single data change, also the example use angular 1.3 now and everything is working like it should be.

shivaprakashboss commented 6 years ago

somehow it is not working in our project. i have tried to implement as like in the link but unable to succeed.

shivaprakashboss commented 6 years ago

what might be the issue why i am not able to implement the feature which is already existing.

lordfriend commented 6 years ago

Maybe some directive like ng-if or ng-repeat creates a child scope which overrides your name. It's suggested to use controllerAs instead of directly manipulate $scope.

shivaprakashboss commented 6 years ago

sir give me an example how i should use $scope or controller.

shivaprakashboss commented 6 years ago

where i should use this controllerAs ?

lordfriend commented 6 years ago

It really depends on your application design (for example if you set up your controller in ngRoute or ui-router, you should config controllerAs at route config) To be simple, a controllerAs alias can be treated as a model in $scope which all other model is its property. Here is an article talk about this topic. https://johnpapa.net/angularjss-controller-as-and-the-vm-variable/

shivaprakashboss commented 6 years ago

Ok I will try and update the behaviour thanks.