Combining two fields to insert/update column - preSubmit?
Combining two fields to insert/update column - preSubmit?
peterbrowne
Posts: 314Questions: 54Answers: 0
in Editor
I want to combine two fields to insert/update:
program_outcome.program_outcome + program_outcome.type => program_outcome.program_outcome_full
I want this to be done invisibly based on the values of program_outcome and type in the editor. I'm assuming that I will need to use preSubmit, but not sure if this is correct or how to use it in this context.
Server side:
Editor::inst( $db_cm_dopt, 'program_outcome', 'program_outcome_pk' )->fields(
Field::inst( 'program_outcome.program_outcome' ),
Field::inst( 'program_outcome.type' ),
Field::inst( 'program_outcome.modified' ),
Field::inst( 'program_outcome.modified_by' )->setValue( $user ),
Field::inst( 'program_outcome.program_outcome_group_fk' )
->options( Options::inst()
->table( 'program_outcome_group' )
->value( 'program_outcome_group_pk' )
->label( 'program_outcome_group' )
),
Field::inst( 'program_outcome_group.program_outcome_group' )
)
->leftJoin( 'program_outcome_group', 'program_outcome_group.program_outcome_group_pk', '=', 'program_outcome.program_outcome_group_fk' )
->process( $_POST )
->json();
Client side:
var editor = new $.fn.dataTable.Editor( {
ajax: "program_data/program_outcome_data.php",
table: "#program_outcome_table",
template: '#program_outcome_form',
fields: [ {
label: "Program Outcome:",
name: "program_outcome.program_outcome"
}, {
label: "Type:",
type: "select",
placeholder: 'Select a Type...',
name: "program_outcome.type",
options: [
"OCANZ",
"UWA"
]
}, {
label: "Program Outcome Group:",
name: "program_outcome.program_outcome_group_fk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: false
} ]
} );
editor.on( 'preSubmit', function ( e, d, action ) {
if ( action === 'create' || action === 'edit' ) {
$.each( d.data, function ( key, row ) {
row.program_outcome_full = row.type +'-'+ row.program_outcome;
} );
}
}
var table = $( '#program_outcome_table' ).DataTable( {
responsive: true,
columnDefs: [ {
targets: 0,
render: $.fn.dataTable.render.ellipsis( 100, true )
} ],
ajax: "program_data/program_outcome_data.php",
dom: "Blfrtip",
columns: [ {
data: "program_outcome.program_outcome"
}, {
data: "program_outcome.type"
}, {
data: "program_outcome_group.program_outcome_group"
}, {
data: "program_outcome.modified"
}, {
data: "program_outcome.modified_by"
} ],
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: []
} );
This question has an accepted answers - jump to answer
Answers
An example using the above would be great and save me from asking follow-up questions!
The
Field->setValue()
method on the server-side with a server-side event is how I would approach this*.For example (for
preEdit
-preCreate
would be similar):Regards,
Allan
Okay, but I'm asking this question based on your answer from yesterday, re not having a left join in Mjoin to concatenate two columns in the Mjoin.
The solution just requires showing in the options in the select list for
program_outcome
in that previous question, as concatenated fields from the two columnsprogram_outcome.type
andprogram_outcome.program_outcome
.Oh I see! I misunderstood the question yesterday in that case. If this is for the list of options, then you can use a renderer for that. The third example there shows how that can be done.
Allan
Thanks Alan, that did the trick easily!