Auto-Complete Hidden ID Field

mjda

Well-known member
Licensed customer
This may not be something that's needed for many but I thought I'd give it a shot anyways because I've come across two different use-cases myself. It would be nice if, when using auto-complete, we could specify a data-hidden-id-field, or something similar, that could be updated when an auto-complete target is selected.

I'm thinking we could write something like this:

Code:
<xf:textboxrow name="item" label="Item" explain="Enter your item name."
    id="js-ItemSelector"
    ac="single"
    data-acurl="{{ link('addon/item/auto-complete') }}"
    data-hidden-id-field=".js-HiddenItemId" />
<xf:hiddenval name="item_id" class="js-HiddenItemId" value="" />

Once the "item" row is updated with the text, then the javascript could also update the "item_id" field with the id that's returned in the response params. There may be better ways to implement this, but the idea is simply that we can update a field to include the item_id rather than the text response, while still keeping the text in the textbox so users don't get confused.
 
Upvote 0
Maybe i'm not understanding the use case, but why wouldn't you just let the DB decide the next ID on insert instead of sending one in manually that might not ever get saved/waste a number?
 
Maybe i'm not understanding the use case, but why wouldn't you just let the DB decide the next ID on insert instead of sending one in manually that might not ever get saved/waste a number?

I use this for searching data that already exists in the database, not inserting new items into the database. I'm combining two columns into the auto-complete box so folks won't get confused $text = "{$car->year} {$car->make} {$car->model}";. However, when I click submit, now I need to search the database for the row where the year/make/model match. Not a huge deal because there's a unique index on that anyways, but it would be better, in my opinion, if I could be submitting the car_id into the form instead to make absolutely certain I'm getting the right row.

As I said, maybe I'm the only one who can use this so it wouldn't be worth spending the time. But I have seen a few other threads where folks asked how to do this and, as far as I know, there isn't already a way to do it so I posted the suggestion. If it gets implemented, great! If not, that's fine too. I'll work around it like I do now.
 
Last edited:
Back
Top Bottom