fill type:select with conditional data
fill type:select with conditional data
Hello all, I would like to know how I can populate a select field with conditional data,
But how can I do it in datatables? For example:
Editor::inst( $db, 'users' )
->field(
Field::inst( 'users.first_name' ),
Field::inst( 'users.last_name' ),
Field::inst( 'users.phone' ),
Field::inst( 'users.site' )
->options( Options::inst()
->table( 'sites' )
->value( 'id' )
->label( 'name' )
)
->validator( 'Validate::dbValues' ),
Field::inst( 'sites.name' )
)
->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
->process($_POST)
->json();
Suppose table sites also had a column named visible, so I want to make a "where" condition on the joined table
According to the manual I can use this but where to put it ?
$editor->where( 'visible', 0 );
This question has an accepted answers - jump to answer
Answers
I have this now:
`// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'bezoekverslagen', 'bezoekverslagen_id' )
->fields(
Field::inst( 'bezoekverslagen.dealernr' ),
Field::inst( 'bezoekverslagen.beschrijving' ),
Field::inst( 'bezoekverslagen.afspraak' ),
Field::inst( 'bezoekverslagen.opvolgen' ),
But I think this only filters what I see in the table and not what I can select when creating a new record. I hope someone can help, thanks!
"But I think this only filters what I see in the table and not what I can select when creating a new record."
You are exactly right!
Just take a look at my first reply in this post and you should find everything you need including a little more complex rendering of the options. There is only one limitation: Your WHERE clause must be a closure function in options! (But only there fore everyhting else you can use the "normal" WHERE clause as above.)
https://datatables.net/forums/discussion/comment/116681/#Comment_116681
Prettig weekend!
Dear rf1234, that looks good! thanks I will try that.
U ook prettig weekend!