indrimuska / angular-selector

A native AngularJS directive that transform a simple <select> box into a full html select with typeahead.
http://indrimuska.github.io/angular-selector
MIT License
96 stars 36 forks source link

Select Boxes with Remote Still Query While Disabled #20

Closed scirelli closed 8 years ago

scirelli commented 8 years ago

I have form fields that are hidden until the user chooses to fill out more advanced fields. i don't want these fields to make remote requests until they are available to the user. I assumed using disable, or disabled would stop the remote query, but it does not. Is there a way to prevent the selector from querying the server until I want it to?

indrimuska commented 8 years ago

Hi Steve, you say that, even if the selector is disabled, you have some extra remote requests in your app. I have just created this plunker to verify the issue, but I can't see anything wrong in it. Can you give me a working example to check this behavior?

Anyway, you could simply wrap your selector and append a regular ng-if attribute to show/hide the entire selector.

scirelli commented 8 years ago

Open a debugger, go to the network tab, clear it, refresh the plunker page. The select box is disabled, but you see the first request "http://services.groupkt.com/country/search?text=" which fills the selectbox.

What I was hoping was that when the selectbox was disabled or hidden it would not make any queries.

In my case, as the user is filling out the form, the select boxes will update based on the previous selection. Kind of like a waterfall flow. What I don't want is when the form first loads, all the select boxes make their first query to fill themselves. Since the httpconfig on the select box doesn't have all the info, the request will just error.

What I do is have a watch, so that when one model changes I grab the items I need from it, update the next select box's httpconfig, and then I call fetch.

On Sat, Feb 20, 2016 at 6:14 PM, indrimuska notifications@github.com wrote:

Hi Steve, you say that, even if the selector is disabled, you have some extra remote requests in your app. I have just created this plunker http://plnkr.co/edit/1pvaCDBDEJSwUlFeaieS?p=preview to verify the issue, but I can't see anything wrong in it. Can you give me a working example to check this behavior?

Anyway, you could simply wrap your selector and append a regular ng-if attribute to show/hide the entire selector.

— Reply to this email directly or view it on GitHub https://github.com/indrimuska/angular-selector/issues/20#issuecomment-186700280 .

Steve Cirelli Cell: 347-618-1144 KK4FRG

Email Charter http://emailcharter.org/

indrimuska commented 8 years ago

Well, you're right. After initialization, the selector fetches data for the first time to populate the list. Anyway I don't know if this behavior needs to be avoided.

However, have you tried using a ng-if wrapper like this?

<div ng-if="!disabled">
    <select selector ...></select>
</div>

Check out this updated plunker and let me know if this fits your needs.

scirelli commented 8 years ago

I probably could. I'll give it a shot. Thanks!

On Sun, Feb 21, 2016 at 5:22 PM, indrimuska notifications@github.com wrote:

Well, you're right. After initialization, the selector fetches data for the first time to populate the list. Anyway I don't know if this behavior needs to be avoided.

However, have you tried using a ng-if wrapper like this?

Check out this updated plunker http://plnkr.co/edit/1pvaCDBDEJSwUlFeaieS?p=preview and let me know if this fits your needs.

— Reply to this email directly or view it on GitHub https://github.com/indrimuska/angular-selector/issues/20#issuecomment-186932282 .

Steve Cirelli Cell: 347-618-1144 KK4FRG

Email Charter http://emailcharter.org/

indrimuska commented 8 years ago

In the end, I decided to patch this behavior. Give it a try and let me know if everything is ok!