How can I display multiple options names in the column?
How can I display multiple options names in the column?
Hi:
I have implemented a select field with the multiple property but I'm only getting the first name of the first option selected.
JS code:
{
label: "Fraccionamiento",
name: "promociones.idFraccionamientos",
type: "select",
placeholder: "Selección",
multiple: true,
separator: ','
}
PHP code:
Field::inst( 'promociones.idFraccionamientos' )
->validator( 'Validate::notEmpty',
array(
"message" => "Campo obligatorio"
))
->options( 'fraccionamientos', 'idFraccionamientos', 'nombre', function ($q) {
$q ->where('fraccionamientos.estatus', 'Habilitado', '=');
} )
->validator( 'Validate::dbValues' ),
Field::inst( 'fraccionamientos.nombre' ),
The field idFraccionamientos is a VARCHAR field and it saves the data as:
1,2,3
The number is the primary ID of a table named fraccionamientos and I get the field nombre to display the name.
Hope you can help me out.
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Its a bit trickier here since you aren't using referential integrity in the database. So what you need to do is use a renderer to split the integer string and then loop over the array looking up the label for each integer.
The way to do the look up is to listen for the
xhr
event and assign the list of options to a variable that is scoped for both that event handler and the renderer - e.g.:The look up is left as an exercise ;-)
Allan
Thanks Allan!