-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autocomplete Field #243
Comments
See in smbo project:
classes for example. Also this nasty issue of Semantic Semantic-Org/Semantic-UI#2072 and solution/workaround which works in smbo in practice: Semantic-Org/Semantic-UI#2072 (comment) |
Start taking a look at dropdown from semantic ui and did a bit of testing. Here what I find out so far The HTML structure generate for this input field should look like this: <div id="input_id" class="ui search selection dropdown">
<input class="search"></input>
</div> Note: the class name are important, even for the Input element using 'search', when calling $('#input_id').dropdown() for autocomplete to work. Otherwise, you just get a regular dropdown. Here is the structure of data that the dropdown will accept:
Note that the fields structure must be pass in as the 'Fields' option when calling $.dropdown()
mockResponse can be used instead of an url in apiSettings to simply test the dropdown without calling the server. In real scenario, replace mockResponse with url in apiSettings like this:
@romaninsh, @DarkSide666 - That should be the basis of the AutoComplete. Not sure yet about how to implement this to generate proper HTML into the page and properly generate the callback to return the json results. Would you take care of that part? I can make sure js will work fine from there. |
Not clear what's needed. Isn't search() taking care of that already? Why does it have to generate HTML? other than that, if you can provide a reference HTML + JS, I can probably get it sorted inside PHP. |
From what I understand, semantic ui dropdown module is more appropriate then search module to achieve what you need. Basically, the AutoComplete field class should render html like describe above, so when executing the js action for the dropdown, semantic will know what to do base on the html attribute class value. So hypothetically, the AutoComplete.php class would look like this: <?php
namespace atk4\ui\FormField;
use atk4\ui\Form;
class AutoComplete extends Input
{
public $defaultTemplate = 'formfield/autocomplete.html';
public $ui = 'ui search selection dropdown';
public function init()
{
parent::init();
$this->jsInput(true)->dropdown([
'fields' => ['name' => 'name', 'value'=>'id'],
//setup url that will generate json data.
'apiSettings' => ['url' => $this->getCallbackUrl()],
]);
} Then the autocomplete.html template file would look like this:
|
yes, that's about right 👍 |
Just for reference this is how I implemented that in smbo project. That's definitely not perfect, but it works (somehow) :)
|
Thanks @DarkSide666 ; I have manage to make it works in FormField/AutoComplete.php in branch feature/autocomplete-field. Although it is now using mock data, what is needed to do now is too pass in an url instead of mock data. But I am a bit mix up on how to implement that within the field. I am guessing a callback url but how do you connect that to the field model so it return json from it.... |
As we have the Lookup FormField doing this nicely, can we close here? |
Our standard field for relations (hasOne) has been a dropdown. This is limiting because it must load all the options right away.
Autocomplete field is always in a very high demand, so this ticket specifies how it should be created.
Semantics
FormField\AutoComplete should either extend \FormField\Dropdown or Input\Generic, whichever suits. Adding it to the form should be possible like this:
If form does not use model, it should still be possible to use AutoComplete.
It's important that AutoComplete work only with Models (no raw data sources) because it must use call-back for loading data.
Look and Feel
We would like to use a standard field, to keep it consistent with the rest of the form. User should still be able to specify an icon, like with regular input fields:
When typing entry, we can use
search()
api to perform back-end query using URL provided by a Callback class. The results should be limited to 50 records ($this->recordLimit).Matching search should be performed against $title column of the model by using
($m->title, 'like', '%'.$q.'%);
, then calling setLimit() and export([$m->id_field, $m->title_field]);The response JSON should be structured like this potentially allowing more fields:
Add button
A must-have feature is ability to add new record through a Modal dialog. To enable, user should pass extra argument:
This would add a button to the right of the field with a plus on it. User should also be able to specify a custom icon. I recommend if the custom icon is specified, we would combine it with a "corner plus" icon. https://semantic-ui.com/elements/icon.html#/definition - see corner icons. (Optional)
Add button should open Modal window referencing it's own call-back code with a form. Upon form submission, window should close, notification should be displayed, that new client is added and the opening field should automatically select new record.
Stability
It should be possible to have multiple AutoComplete buttons on a form, without clashing.
The text was updated successfully, but these errors were encountered: