Hello community,
I’m stuck for a long time with one thing I cannot solve, AI also run out of suggestions in this case. As I understand autocomplete component has a hard limit on this. What I want to achieve is to have a text input field that suggest autocomplete list and should work this way:
- If user types and gets suggested text from the DB (that has a value) and clicks on it then it stays - this works perfect with autocomplete - no issues here;
- If the user types and gets no suggestions then his typed text should be stored to the DB and then loaded from the DB . For autocomplete component this is probably a hard limit and I do not find a way to handle this.
In my example I want a user to be able to select specialty from the list or input his own if no suggestions is there. For this goal I use specialty_id and specialty_text and .json saves either the specialty_text or specialty_id. But the issue is when I try to load specialty_text from the DB to autocomplete it does not show up, I’ve tried using search/text input fields, mixing them but then I get no suggestions and so on.
I’m using a datastore to save those values and these specialties are inside a modal’s repeat children, the component iself code:
<input id="autocomplete_specialty" name="specialty_text" class="form-control" is="dmx-autocomplete" placeholder="įrašykite arba pasirinkite" dmx-bind:data="conn_values.data.query_specialty" optiontext="specialty" noclear="true" noresultslabel="" dmx-on:changed="ds_educations.update({$id: $value.$id},{specialty_text: value, specialty_id: value.match(/^\\d+$/)?value.toNumber():null})" data-rule-pattern="^(\[A-Za-zĄČĘĖĮŠŲŪŽąčęėįšųūž\\- \]+|\\d+)$" data-msg-pattern="Neleidžiami simboliai" type="search" optionsearch="specialty" dmx-bind:value="specialty_text" dmx-on:blur="ds_educations.update({$id: $value.$id},{specialty_text: value, specialty_id: value.match(/^\\d+$/)?value.toNumber():null})" optionvalue="specialty_id" >
server response when loading existing values looks like this:
- For an autocomplete where specialty_id had a value (record in the DB) and selected from autocomplete it works and display correctly:
"specialty_id": null,
"specialty_text": "1",
2. For an autocompelte where specialty_id had no value (no record in the DB) so specialty_text was inserted in the DB does not display it in the autocomplete component:
"specialty_id": null,
"specialty_text": "geras",
Payload array when sending the value that is inside the DB (specialty_id):
"specialty_id":null,"specialty_text":"3"
Payload array when sending only specialty_text that has no specialty_id in the DB:
"specialty_id":null,"specialty_text":"geras" - this text also dissapears when leaving the the fild (no clear is checked).