Select with a label that includes information from two different tables.
Select with a label that includes information from two different tables.
Gargiucn
Posts: 109Questions: 30Answers: 0
I refer to the following old discussion:
https://datatables.net/forums/discussion/44483
I couldn't figure out how to do it and I think it would be very useful to have an example.
I stopped here:
Field::inst( 'pagamenti.pag_idcontr' )
->options( function(){
global $db;
return $db->sql( 'SELECT contratti.con_num, clienti.cli_ragsoc FROM clienti INNER JOIN
contratti ON clienti.cli_id = contratti.con_cli' )->fetchAll();
} )
->validator( Validate::dbValues()
client side:
fields: [
{
label: "Contratto",
name: "pagamenti.pag_idcontr",
type: "select",
placeholderDisabled: false,
placeholder: "Seleziona..."
},
...
The field "contratti.pag_idcont" should have a label that displays together:
"contratti.con_num" and "clienti.cli_ragsoc".
Your help will be greatly appreciated...
Giuseppe
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I believe I have solved it:
I hope he can help someone ...
Giuseppe
Hi Giuseppe,
Perfect - thanks for posting your solution. That looks good to me. You might be able to do
function () use ($db) {
rather than accessing it from global scope, but that's the only thing I'd change.Allan
I thought I had done a good job, the select works fine on its own but within my program it generates the following error:
This is the php script:
Sigh...
That's this line.
Its throwing an error because it can't get the information needed for the validator from the
Options
class.What you can do is pass in the table name and column to check against for the validation using the options for the
dbValues
validation method.Allan