When model has belongs_to association, in create and edit action there will be combo box that helps to associate other model to this. I have found out that field for assigning models are more complicated than I thought.
According to source code of this field:
It has hidden <select> tag that keeps all avilable values.
Users sees <input> tag which has javascript for autocomplete
When users clicks to drop-down button or types to input, it creates dynamically <ul> tag with available elements.
When users choose one of options some kind of javascript method changes <select> tag's value.
I think this field uses JQueryUI's autocomplete library. It loads ALL available models that could be associated.
However, this gives new problem. For example:
If I have models Shop, Item and Category. They have these associations:
Shop has_and_belongs_to_many Categories
Shop has_many Items
Category has_many Items
When Users creates his own Shop he associates multiple Categories. Then Users tries to create Item and he need to choose Shop and Category. Combobox shows ALL available Categories for Item creation.
I need to show only categories that has selected Shop. imagine if there are 1000 Categories and Shop has only 3 of them.
I have created my own ui.js javascript file in assets/javascripts/rails_admin/custom/ directory. Created AJAX functions that will change values of <select> tag by value of other <select> tag. However, it DOES NOT change available values for autcomplete.
I think script for autocomplete preloads all data when page is loaded and works independently from values of <select> tags.
Is it possible to reaload avaliable data for autocomplete input?
Hello.
When model has
belongs_to
association, increate
andedit
action there will becombo box
that helps to associate other model to this. I have found out that field for assigning models are more complicated than I thought.According to source code of this field:
<select>
tag that keeps all avilable values.<input>
tag which has javascript for autocomplete<ul>
tag with available elements.<select>
tag's value.I think this field uses JQueryUI's autocomplete library. It loads ALL available models that could be associated.
However, this gives new problem. For example:
If I have models
Shop
,Item
andCategory
. They have these associations:has_and_belongs_to_many
Categorieshas_many
Itemshas_many
ItemsWhen Users creates his own Shop he associates multiple Categories. Then Users tries to create Item and he need to choose Shop and Category. Combobox shows ALL available Categories for Item creation.
I need to show only categories that has selected Shop. imagine if there are 1000 Categories and Shop has only 3 of them.
I have created my own
ui.js
javascript file inassets/javascripts/rails_admin/custom/
directory. Created AJAX functions that will change values of<select>
tag by value of other<select>
tag. However, it DOES NOT change available values for autcomplete.I think script for autocomplete preloads all data when page is loaded and works independently from values of
<select>
tags.Is it possible to reaload avaliable data for autocomplete input?