Mjoin - Not inserting or updating, but delete works
Mjoin - Not inserting or updating, but delete works
I have multiple Mjoins in a script, they all work properly except for one, which doesn't do any inserts or updates into the lookup joined table.
If I manually add the data through phpMyAdmin into the lookup table, datatables and the editor field see this OK. I can also do a delete through datatables, and the record is deleted, including in the associated lookup table.
The problem Mjoin is Mjoin::inst( 'learning_event_type' )
The others work fine...
Client side:
<div class='table_container'>
<table id='learning_event_table' class='display' style="width:100%">
<thead>
<tr>
<th>Learning Event</th>
<th>Outline</th>
<th>Program Outcome</th>
<th>Unit Group</th>
<th>Presentations</th>
<th>Conditions</th>
<th>Type</th>
<th>Modified</th>
<th>Modified By</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div id="learning_event_form">
<editor-field name="learning_event.learning_event_name"></editor-field>
<editor-field name="learning_event.outline"></editor-field>
<editor-field name="program_outcome[].program_outcome_pk"></editor-field>
<editor-field name="learning_event.unit_group_fk"></editor-field>
<editor-field name="learning_event.learning_event_outcome"></editor-field>
<editor-field name="presentation[].presentation_pk"></editor-field>
<editor-field name="mcondition[].mcondition_pk"></editor-field>
<editor-field name="learning_event_type[].learning_event_type_pk"></editor-field>
</div>
</div>
<script type="text/javascript">
var editor; // use a global for the submit and return data rendering in the examples
$( document ).ready( function () {
var program = $( '#program_field' ).val();
var user = $( '#user_field' ).val();
var permission = $( '#permission_field' ).val();
$( '#main-menu' ).smartmenus();
$( '#program_levels' ).change( function ( e ) {
window.location.href = 'edit_' + this.value + ".php?program=" + program + '&user=' + user;
} );
// Edit record
$( '#learning_event_table' ).on( 'click', 'a.editor_edit', function ( e ) {
e.preventDefault();
editor.edit( $( this ).closest( 'tr' ), {
title: 'Edit record',
buttons: 'Update'
} );
} );
$.fn.dataTable.Editor.display.lightbox.conf.windowPadding = 50;
var editor = new $.fn.dataTable.Editor( {
ajax: "program_data/learning_event_data.php",
table: "#learning_event_table",
template: '#learning_event_form',
fields: [ {
label: "Learning Event:",
name: "learning_event.learning_event_name"
}, {
label: "Outline:",
name: "learning_event.outline",
type: "ckeditor"
}, {
label: "Program Outcome:",
name: "program_outcome[].program_outcome_pk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: true
}, {
label: "Unit Group:",
name: "learning_event.unit_group_fk",
type: "select",
placeholder: "Select Unit Group..."
}, {
label: "Presentations:",
name: "presentation[].presentation_pk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: true
}, {
label: "Conditions:",
name: "mcondition[].mcondition_pk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: true
}, {
label: "Type:",
name: "learning_event_type[].learning_event_type_pk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: false
} ]
} );
var table = $( '#learning_event_table' ).DataTable( {
responsive: true,
"autoWidth": false,
"lengthMenu": [
[ 5, 10, 25, 50, -1 ],
[ 5, 10, 25, 50, "All" ]
],
columnDefs: [ {
targets: 1,
render: $.fn.dataTable.render.ellipsis( 150, true )
} ],
ajax: "program_data/learning_event_data.php",
dom: "Blfrtip",
columns: [ {
data: "learning_event.learning_event_name",
width: '15%'
}, {
data: "learning_event.outline",
width: '15%'
}, {
data: "program_outcome",
render: "[, ].program_outcome"
}, {
data: "unit_group.unit_group"
}, {
data: "presentation",
render: "[, ].presentation_name"
}, {
data: "mcondition",
render: "[, ].mcondition_name"
}, {
data: "learning_event_type",
render: "[, ].learning_event_type_name"
}, {
data: "learning_event.modified"
}, {
data: "learning_event.modified_by"
}, {
data: null,
className: "center",
defaultContent: '<a href="" class="editor_edit">Edit</a>'
} ],
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: []
} );
This question has an accepted answers - jump to answer
Answers
Server side:
The response from XHR:
As you can see the
learning_event_type
data (at the bottom) is empty, even though the select in the editor was populated from the problematic Mjoin, and an option in that select list selected.Hi,
Thanks for all the details! Could you also show me the request parameters that Editor is sending to the server please? I just want to make sure that
learning_event_type
is being submitted.Thanks,
Allan
Like this?
Thank you. That shows that the problem is client-side - the:
is wrong for an mjoin submit.
I suspect the issue is with:
for that field. As an experiment, can you remove that please?
Allan
Thanks Allan. Removing
multiple:false
fixed it. So I now have:But how can I make the select single select only?
Add:
To the field's object, and that will do the trick.
Allan
Sorry Allan, but now the code I thought was working above (last post) doesn't (no update or insert for
learning_event_type[].learning_event_type_pk
) work unless I change it to includemultiple: true
Adding the attr still has multiple select options...as I would expect.
Seems like a simple thing I have had working in the past...
Can you show me what the client is submitting when you have:
please?
Thanks,
Allan
Two options selected in the learning_event_type multiple select list with
Result is the two options added to the database:
Apologies - the
size
attribute actually only effects the display height of the element (and can be overridden by CSS).Digging through it, at this time there isn't a way to show a select with a dropdown (i.e. not multiple) for use with an Mjoin - which is specifically designed to expect multiple options.
Would a valid option be to add a server-side validator to ensure that [only one option is selected](https://editor.datatables.net/manual/php/validation#One-to-many-(Mjoin)?
Allan
Thanks Allan for the clarification. It's not really an issue having a multiple select, just a preference for having a single select option. I can live with the multiple.
Thanks for your help!
Peter