I need to make a field that dynamically offers possible options as you type. I found a flexdatalist , and everything would be fine, but I can not previously insert data into the field - the script deletes everything.
Here is the part of the documentation that describes what I need. enter image description here I do everything the same way as in the documentation, but it simply displays an empty field.
Part of the code:

<input value='{$content[0]['disease_id']}' type="text" class="form-control flexdatalist" id="disease_id" name="disease_id" data-url='/json?get=diseases' data-search-in='name' data-text-property='name' data-visible-properties='["name"]' data-selection-required='true' data-value-property='id' data-min-length='0' required> 


Who worked with flexdatalist, tell me, what am I doing wrong, or what is an alternative to this (there must be support for choosing several values)?
How to be?

  • Have you checked if json is catching up at /json?get=diseases and is it valid? Add sample data to the question - Darth
  • Checked the data in the same format as in the docks. When I will add at home. - AndiS
  • What is not satisfied with this decision? jqueryui.com/autocomplete - Vasya Milovidov
  • In your solution, is it possible to send an object id when choosing its name from the list? That is, if the data is in this format: "[{" id ": 1," name ":" Sergey "}, {" id ": 2," name ":" Vlad "}] and the object named Sergey is selected, then the unit should be sent to the server - AndiS
  • I think there is no such solution out of the box, but what prevents you from creating a dictionary of matches id -> name, and if the user chose some name value, would it uniquely be mapped to an id bound to this name? And then send this id to the server? - Vasya Milovidov

1 answer 1

 <!-- Π’ΠΈΠ΄ΠΆΠ΅Ρ‚ autocomplete ------------------- Π’ΠΈΠ΄ΠΆΠ΅Ρ‚ "autocomplete" позволяСт ΡƒΡΠΊΠΎΡ€ΠΈΡ‚ΡŒ Π²Π²ΠΎΠ΄ Π΄Π°Π½Π½Ρ‹Ρ… Π² ΠΏΠΎΠ»Π΅, отобраТая ΠΏΠΎ ΠΌΠ΅Ρ€Π΅ ввСдСния ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½Ρ‹Π΅ прСдполоТСния. Π’Ρ‹Π±Ρ€Π°Π² ΠΎΠ΄Π½ΠΎ ΠΈΠ· ΠΏΡ€Π΅Π΄ΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ ΠΌΠΎΠΆΠ΅Ρ‚ автоматичСски Π·Π°Π²Π΅Ρ€ΡˆΠΈΡ‚ΡŒ Π²Π²ΠΎΠ΄. ΠŸΡ€Π΅Π΄ΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΡ выводится Π² случаС, Ссли Π΄Π°Π½Π½Ρ‹Π΅ Π²Π²Π΅Π΄Π΅Π½Π½Ρ‹Π΅ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΌ ΡΠΎΠ²ΠΏΠ°Π΄Π°ΡŽΡ‚ со Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ΠΌ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· элСмСнтов ΠΈΠ· списка Π΄Π°Π½Π½Ρ‹Ρ…. Π’Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Ρ‚ΡŒ ΠΊ Π²ΠΈΠ΄ΠΆΠ΅Ρ‚Ρƒ ΠΊΠ°ΠΊ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ (Ρ‚.Π΅. ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½Ρ‹Π΅ Π² скриптС Π½Π° этой ΠΆΠ΅ страницС) Ρ‚Π°ΠΊ ΠΈ ΡƒΠ΄Π°Π»Π΅Π½Π½Ρ‹Π΅ списки (Ρ‚.Π΅. находящиСся Π½Π° ΡƒΠ΄Π°Π»Π΅Π½Π½ΠΎΠΌ сСрвСрС). Π›ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ списки ΡƒΠ΄ΠΎΠ±Π½Ρ‹ для хранСния Π½Π΅Π±ΠΎΠ»ΡŒΡˆΠΈΡ… Π½Π°Π±ΠΎΡ€ΠΎΠ² Π΄Π°Π½Π½Ρ‹Ρ… (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ список ΡƒΠ»ΠΈΡ† Π³ΠΎΡ€ΠΎΠ΄Π°), Π° ΡƒΠ΄Π°Π»Π΅Π½Π½Ρ‹Π΅ списки подходят для хранСния Π±ΠΎΠ»ΡŒΡˆΠΈΡ… Π½Π°Π±ΠΎΡ€ΠΎΠ² Π΄Π°Π½Π½Ρ‹Ρ… (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π±Π°Π·Π° Π΄Π°Π½Π½Ρ‹Ρ… всСх Π³ΠΎΡ€ΠΎΠ΄ΠΎΠ² ΠΌΠΈΡ€Π°). Бинтаксис: /* 1. ΠžΠΏΡ€Π΅Π΄Π΅Π»ΡΠ΅ΠΌ элСмСнт input, Π² ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡ‚ΡŒΡΡ Π²Π²ΠΎΠ΄ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ */ <input id='auto' /> /* 2. ΠŸΡ€Π΅Π²Ρ€Π°Ρ‰Π°Π΅ΠΌ input Π² Π²ΠΈΠ΄ΠΆΠ΅Ρ‚ autocomplete */ $('#auto').autocomplete({опция1:Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅1,опцияN:Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅N}) ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ ΠΊ Π²ΠΈΠ΄ΠΆΠ΅Ρ‚Ρƒ список Π΄Π°Π½Π½Ρ‹Ρ… ΠΌΠΎΠΆΠ½ΠΎ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ΠΎΠΏΡ†ΠΈΠΈ source. Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ΠΎΠΏΡ†ΠΈΠΈ minLength Π’Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ минимальноС количСство символов, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ ΠΏΠΎΠ»Π΅ Π²Π²ΠΎΠ΄Π° ΠΏΡ€Π΅ΠΆΠ΄Π΅, Ρ‡Π΅ΠΌ поиск совпадСний Π½Π°Ρ‡Π½Π΅Ρ‚ выполнятся. --> <!DOCTYPE html> <html> <head> <title>UI 2-2-1</title> <meta charset="utf-8" /> <link rel="stylesheet" href="css/jquery-ui.min.css"> <script src="js/jquery-3.2.1.min.js"></script> <script src="js/jquery-ui.min.js"></script> <script> $(function () { $("#auto1").autocomplete({ source: ["Π”ΠΌΠΈΡ‚Ρ€ΠΈΠΉ", "ΠœΠ°Ρ€ΠΈΡ", "Π’Π»Π°Π΄ΠΈΠΌΠΈΡ€", "АлСксСй", "Π•ΠΊΠ°Ρ‚Π΅Ρ€ΠΈΠ½Π°", "ОлСг", "Ольга"] }); }); </script> </head> <body> Π’Π²Π΅Π΄ΠΈΡ‚Π΅ имя: <input id="auto1"> </body> </html>