autocomplete posts V, not K

Questionsautocomplete posts V, not K
Peter Broekman asked 4 years ago

Abu,

below posts the V value, not the K (so  [ProjectNumber]+’ – ‘+[ProjectName] ). Ofcourse can do after_insert stuff, but why does this work differently than a select alternative, which is user unfriendly?

 

$colb[“formatter”] = “autocomplete”; // autocomplete

$colb[“formatoptions”] = array( “sql”=>”SELECT DISTINCT ProjectNumber AS k, [ProjectNumber]+’ – ‘+[ProjectName] AS v
FROM Y_MD_ProjectForeCastSystem order by ProjectNumber”, “search_on”=>”concat(ProjectNumber,’ – ‘,ProjectName)”);

5 Answers
Abu Ghufran Staff answered 4 years ago

Option 1: In autocomplete, you can specify another field (client_id) that will be filled with K (key) values after selection and it can be posted as well.

$col[“formatoptions”] = array(“sql”=>”SELECT client_id as k, name as v FROM clients”, “update_field”=>”client_id“);

Option 2: Use select2 dropdown. It has default functionality to show label and post key on backend. Refer demos/integration/dropdown-select2.php

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Peter Broekman answered 4 years ago

yeah well, option 2 is not really userfriendly, and suppose you have table where projectmumber is key and the projectname you have in a seperate masterdat table. Ofcourse you want to show the name, but soonest you put than on editable, record gets stuck on insert as well (as it’s not part of the updated table) . Everybody that saves names in linked tables (which in a way seems normal practice) has the same problem. The as k as v you present in the demo, is  kind of suggesting that the logic would work as with option 2. But ok i take it as given for now,

Abu Ghufran Staff answered 4 years ago

The limitation we have here is auto complete is applied on input box which can have one value, either key or value. Where as drop-down can have two value and key/value post/display is doable there. Hope you understand.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Peter Broekman answered 4 years ago

Yes, ok limitation of the html type, got it, tnx

Peter Broekman answered 4 years ago

ok I will use option 1 and add a dummy column in my table that can be edited. Problem with virtuals you make editable is they crash on saving. Thanks for the tip!!!

Your Answer

7 + 11 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?