Autocomplete value to array

Hello!

Is possible record autocomplete text field to an array? I’m creating a form where will be possible to create more than 1 category per video and the categories are stored in my database. Then, I’m planning to do a repeat on server side and record data on my many-to-many table using the array items.

Best

Just checking I am understanding your question correct.

You have a database with categories listed, the form the user is on can assign more than one of the categories from the database to a single video.
You want to know if the categories the user has chosen can be stored in a single database field as category1,category2,category6,category9

Am I understanding that correct?

Hello Paul!
Thanks for your time!

Actually, I have a “Video” table, a “Category Table” and “Video-Category” Table.
I would like to use the “AutoComplete” on the “Video” form to select one category and then store it on a Array, if user wants to add one more category to the video, he would use the autocomplete field again to select one more category and so on…

Hi Otavio

So it sounds like it should be pretty easy to do

  1. Add an empty “Array” to your page
  2. Add an “Auto Complete” component
  3. Select the “Auto Complete” component and enter your
    • Data Source
    • Text Field
    • Value Field
      Add a “Dynamic Event” of “Data, Value Changed” and set the action to “Array, Add Unique Item” then choose a Value Property, which will be the value of the “Auto Complete”
      To see what is going on, add a binding on your page of “Array > Items” which will then update to show each value as it gets pushed into the array.

The one thing this does not do is clear the “Auto Complete” field after an item is added to the Array, so your user needs to remove what was there previously and add their next value.

Alternatively you could place your Auto Complete in a form and clear the form after each option chosen, personally I do not do it this way because normally my form has other data I do not want to be cleared at that stage.

My suggestion would be to select your array, and add a dynamic event of “Value Updated” with an action to Set Value of the auto complete to nothing/blank

Your final code would look something like

<input id="autocomplete1" name="autocomplete1" is="dmx-autocomplete" dmx-bind:data="sc_landlord_codes.data.apiSummary.data" optiontext="title" optionvalue="landlord" dmx-on:changed="arr1.addUniq(value)">
<dmx-array id="arr1" dmx-on:updated="autocomplete1.setValue()"></dmx-array>
{{arr1.items}}
3 Likes

Paul! Wow! Awesome!! Thank you very much!!
I didn’t know about the “value change” event!

all the best!