OptimalBPM / angular-schema-form-dynamic-select

AngularStrap and AngularUI dynamic select implementation(static/sync/async/http, filters) for Angular Schema Form
MIT License
55 stars 45 forks source link

Ui select. ui-select-match && ui-select-choices support #50

Closed franklopez closed 8 years ago

franklopez commented 9 years ago

Is it possible to do this directly in forms:

<ui-select htmlClass="form-control" ng-model="country.selected" theme="bootstrap" ng-disabled="disabled" reset-search-input="false" style="width: 300px;"> <ui-select-match>{{$select.selected.name}}</ui-select-match> <ui-select-choices repeat="country in countries track by $index" refresh="refreshCountries($select.search)" refresh-delay="1000"> <div ng-bind-html="country.name | highlight: $select.search"></div> </ui-select-choices> </ui-select>

Right now i'm using a modal window o suport this, but i could be much clean to have it in forms directly.

nicklasb commented 9 years ago

Eh, I am not sure. Is the explanation to your code that you have a list of countries that you want to select from? And if you start writing the list is filtered?

If that's the case, that is possible, yes. I don't see any other tricks here?

Just as a side note, I would rather store ISO 3166-codes instead of unreliable country names.

franklopez commented 9 years ago

how do I code it in forms? like this: { "type" : "uiselect", "ui-select-match" : "$select.selected.name}" "ui-select-choices": { "repeat": "country in countries track by $index"}, "refresh" : "refreshCountries($select.search)", "refresh-delay":"1000", "bind-html="country.name | highlight: $select.search" }

nicklasb commented 9 years ago

I dont understand, this seems like a completely common case. If you are asking how to use ASFDS, I would recommend reading the documentation section on the UI-select support combined with the sections on the different available callback variants which can be used to populate the list.

Also, please look at the the example for implementations of all modes of operation: https://github.com/OptimalBPM/angular-schema-form-dynamic-select/blob/master/app.js

nicklasb commented 9 years ago

Aha, now I understand. You basically dont do all that. Just provide it a list of values and titles and go using either of the callback models. It will set the model to the value of the title you select See the example at the uiselect implementation: https://github.com/OptimalBPM/angular-schema-form-dynamic-select/blob/master/app.js#L207

ASFDS doesn't use the IMO rather strange select-data-directly-model of ui-select. I have used different gui-select-components in over 20 years, and never before encountered any that works like that. ASFDS works around that by making it use an internal model and manually set the actual model.

franklopez commented 9 years ago

I've tried that, but that list is only updated on creation of the uiselect.

What i want is to have a function called every x miliseconds that calls a server and gets the selected countries avoiding to load the entire table, so I call the server with for example P and i get only the countries starting with P instead of loading the entire table.

right now I'm doing it with a a uiselect defined in a modal window using the template that i posted in the first post and them pass the values to a form string, and value.

If it was possible to have a full uiselect option range available in the form i would not have to use the modal, and it would look a lot nicer.

nicklasb commented 9 years ago

Ok. The refreshDelay is set using form.options.refreshDelay.

Yes, it would be great having all the options settable that way, I have just not had the time for that yet(would not mind a PR or two). One can see which are implemented here(should possibly review the docs): https://github.com/OptimalBPM/angular-schema-form-dynamic-select/blob/master/src/uiselect.html

But I don't really understand anyway, 200 countries in a JSON array with two fields, that is very little data, I would think that querying the backend constantly for that little data would bring far more overhead than just getting them all at once? I mean the countries aren't changed very often?

franklopez commented 9 years ago

But the countries is the smallest field.

I have others like post codes that table has at least 5k records.

nicklasb commented 9 years ago

Aha. Well then, setting form.options.refreshDelay should cause the callbacks of choice to be invoked. It seems to do that in the example, at least.

franklopez commented 9 years ago

I'll try that then @ work tomorrow. thanks for your help.

nicklasb commented 9 years ago

I tried in the example just now, it seems to refresh even if I dont set it. First character i write makes it refresh.

Anyway, I set the option like this:

        {
            "key": "uiselect",
            "type": "uiselect",
            "placeholder": "not set yet..",
            "options": {
                "callback": "callBackSD",
                "refreshDelay": "500"
            }
        },

If you want the request to depend on the content of some other field, you include that in the callback.

nicklasb commented 9 years ago

And since you likely make an asynchronous callback, you should use the callbackAsync instead: https://github.com/OptimalBPM/angular-schema-form-dynamic-select#multiple-select-from-asynchronous-callback

franklopez commented 9 years ago

how can I get the value inside the select the value that i' want to look for? if I choose from my model it hasn't been assigned yet.

nicklasb commented 9 years ago

Sorry, I don't understand. Can you perhaps rephrase that question?

nicklasb commented 8 years ago

Haven't gotten any further response, closing.