Where condition in autocomplete field
Where condition in autocomplete field
KeepMoving
Posts: 28Questions: 7Answers: 0
The autocomplete field is working good but now I have to show users with specific profile using a where condition
I've read the documentation and Im doing somethink like this and doesnt work.
Field:
{
label:" Usuario",
name:"altaestudios.IdUsuario",
type:"autoComplete",
placeholder:"Elija usuario"
},
Field::inst( 'altaestudios.IdUsuario' )
->options( Options::inst()
->table( 'usuario' )
->value( 'IdUsuario' )
->label( 'nombre' )
-where('perfil',2) // where condition not working
)
->validator( 'Validate::dbValues' ),
Field::inst( 'usuario.nombre'),
Field::inst('usuario.apellido'),
table usuario has "perfil" field
Thanks for help
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Could you enable the server-side debug mode and show me the SQL that Editor generates?
Thanks,
Allan
debugSql It says "SELECT DISTINCT
IdUsuario
as 'IdUsuario',nombre
as 'nombre' FROMusuario
WHEREperfil
IS NULL "Thanks!
There is a typo there - a missing
>
. I would have expected that to show as a syntax error, but it would be worth checking. If it wasn't then can you copy and paste the exact code you are using?Allan
Yea I see that but still doesnt work, I get the same Query in debugSQl
thanks for your help
Ah. I've just remembered that the
Options
class needs a function to be given (see the documentation here) - e.g. you might use:Allan
Hey allan any idea why when I select name from autocomplete I get the Id instead name?
Sounds like the label and value might be getting missed up somewhere. Where do you get the Id - does it display where the able should be?
Allan
When I add or edit a record the search filter display name but when I select I get Id instead name
Pic.
I think joins are wrong. I would check with this example :
https://editor.datatables.net/examples/advanced/joinLinkTable.html
sry got not enough time to dig in deeper.It's late here.
What is the library you are using for the AutoComplete? Apologies if you said before, I can't see it above.
Allan
Sry if i'm wrong but i think this join
should be :
Hope this helps.
It was my mistake, thanks for your help