How to 'set text' and 'set selected' for an autocomplete form field with dynamic content taken from DB in edit mode?


#1

I need to ‘set text’ and ‘set selected’ option of semantic ui for dropdowns to work in ATK4 autocomplete?

in semantic the code is like this:

$('.ui.dropdown').dropdown('set selected', your.value).dropdown('set text', your.name)

how can I do the same in ATK4?

I need this to work in edit mode, these autocomplete options are fed from the DB… and I am using CRUD with a Model.

After the records has been saved to the DB I need to edit the record to change something and the autocomplete fields are always showing nothing the value or text are not being rendered in edit mode…

so my questions are?

how can I detect using GRUD with a model the EDIT MODE?
how can I get the value data from the autocomplete field in EDIT MODE?
and how can I get the data from the DB for this autocomplete field to show the text and value after?

and how can I implement these lines below in ATK4 for the autocomplete field?

$('.ui.dropdown').dropdown('set selected', your.value).dropdown('set text', your.name)

thanks for any tips and help!


#2

hey raP have you been able to figure things out yet? I was on vacation so my response is late.

Detect if CRUD is in edit mode
CRUD was using modes in the past, but it was rewritten using VirtualPage. Looking into that, it has property $cb, initialized to Callback. Callback has method triggered() which returns non-empty value.

So for CRUD could be: if ($this->pageCreate->cb->triggered()). This can probably be wrapped up.

Also you can try checking it from inside your UI (e.g. form) by traversing $this->owner.

Get value from autocomplete field
I’d say $autocomplete_field->jsInput()->val() should do the trick like with any fields. It must give you id value of currently selected option. If that’s not working then check issues perhaps someone else is having this issue. I myself am working only on sponsored issues at this time.

Get autocomplete text from DB
That should be $autocomplete_field->model->loadBy($id)->getTitle().

Not sure about the rest.