olton / Metro-UI-CSS

Impressive component library for expressive web development! Build responsive projects on the web with the first front-end component library in Metro Style. And now there are even more opportunities every day!
http://metroui.org.ua/
MIT License
7k stars 1.97k forks source link

data-role="input" data-autocomplete example #1831

Open TorakikiSan opened 2 years ago

TorakikiSan commented 2 years ago

I am trying to use the autocomplete feature but I can't figure out how to do it.

I have a field defined as

<INPUT id = "MACHINE" name = "machine" class = "input-small" data-role = "input"
             data-validate = "maxlength=100" data-cls-input = "text-bold fg-orange"
             data-autocomplete-url = "/ajax.autocomplete.php" data-autocomplete-url-method = "POST"
             data-label = "Machine" data-cls-label = "fg-black" value = "" />

and in the file ajax.autocomplete.php I execute a query in my db which returns a JSon array of the type

{"mrdo": "Mr. Do!", "pacman": "Pac-Man (Midway)", "xevious": "Xevious (Namco)"}

but it seems I don't know the parameter passed as the argument to search with (MACHINE?).

Also I would like to pass the query to execute a parameter, "Language", but I have not found the way to do it (of course if it is possible to do so) and the query would become

select machine, description
from machines m
where description like '%' || $MACHINE || '%' and exists
    (select 1
     from languages ​​l
     where m.machine = l.machine and '$LANGUAGE' = language);

where $MACHINE is the contents of the field and $LANGUAGE would be the parameter I would like to pass.

can you help me?

xscode-auto-reply[bot] commented 2 years ago

Thanks for opening a new issue. The author has been notified and will review it as soon as possible. For urgent issues and priority support, visit https://xscode.com/olton/Metro-UI-CSS or Patreon

olton commented 2 years ago

https://codepen.io/olton/pen/xxOvoLe

olton commented 2 years ago

you must return array from php code

[
"Ukraine",
"USA",
"Canada",
"Marokko",
"Singapur"
]
TorakikiSan commented 2 years ago

I am very happy that you are back and thanks for the reply.

Can I also use a JSON with a "key" too? Example

[
"1": "Ukraine",
"2": "USA",
"3": "Canada",
"4": "Marokko",
"5": "Singapur"
]