PreEdit issues - Joining two columns for insert/update
PreEdit issues - Joining two columns for insert/update
peterbrowne
Posts: 314Questions: 54Answers: 0
in Editor
I'm using the following to insert the values of two columns into another column in the same table using the preEdit function.
It's producing the error:
Fatal error: Call to undefined method DataTables\Editor\Field::on() in /var/www/html/curriculum_mapper/programs/cm_mjd_plmed/program_data/unit_data.php on line 31
Line 31 is the line starting with the preEdit code...
Editor::inst( $db_cm_mjd_plmed, 'unit', 'unit_pk' )
->field(
Field::inst( 'unit.unit_code' ),
Field::inst( 'unit.unit_name' ),
Field::inst( 'unit.points' ),
Field::inst( 'unit.modified' ),
Field::inst( 'unit.modified_by' )->setValue( $user ),
Field::inst( 'unit.year_fk' )
->options( Options::inst()
->table( 'year' )
->value( 'year_pk' )
->label( 'year_name' )
)
->on('preEdit', function ($editor, $id, $values) {
$editor->field('unit.unit_full_name')->setValue(
$values['unit']['unit_code'] . $values['unit']['unit_name']
);
})
->validator( 'Validate::dbValues' ),
Field::inst( 'year.year_name' )
)
->leftJoin( 'year', 'year.year_pk', '=', 'unit.year_fk' )
->join(
Mjoin::inst( 'program_outcome' )
->link( 'unit.unit_pk', 'program_outcome_unit_lookup.unit_fk' )
->link( 'program_outcome.program_outcome_pk', 'program_outcome_unit_lookup.program_outcome_fk' )
->order( 'program_outcome.program_outcome asc' )
->fields(
Field::inst( 'program_outcome_pk' )
->options( Options::inst()
->table( 'program_outcome' )
->value( 'program_outcome_pk' )
->label( array('type', 'program_outcome') )
->render( function ( $row ) {
return $row['type'] . ' - ' . $row['program_outcome'];
} )
->order( 'type' )
),
Field::inst( 'program_outcome' )
)
)
->process($_POST)
->json();
This question has an accepted answers - jump to answer
Answers
Got it working with this with the preEdit placed at the end, and also adding the
Field::inst( 'unit.unit_full_name' ),
field at the top.PreEdit for update is OK, but what about insert/create?? Is that a separate function or can it be combined?
It would be good to have a combined function, but it currently needs to be a separate function,
preCreate
- see manual here.Colin