Dependant for editor - Separate script not populated select list
Dependant for editor - Separate script not populated select list
I have two dependant selects on my Editor. One is working fine, the new one (assessments) is not working:
This is the separate script to get assessments when the learning_event.unit_group_fk
select is selected:
<?php
require_once( '../../../maps/cm_mjd_plmed/connection/connect.php' );
$unit = $_POST['values']['learning_event.unit_group_fk'];
$data = array();
$query = "SELECT * FROM assessment WHERE unit_group_fk = '$unit'";
$result = $connection->query( $query );
while ($row = mysqli_fetch_array($result)) {
$data[] = array("label"=>$row['assessment'], "value"=>$row['assessment_pk']);
}
$temp = array('assessment[].assessment_pk'=>$data);
$json = array('options'=>$temp);
echo json_encode($json);
<?php
>
```
?>
The client side:
<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="learning_event.length"></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.week_fk"></editor-field>
<editor-field name="assessment[].assessment_pk"></editor-field>
<editor-field name="learning_event_type[].learning_event_type_pk"></editor-field>
</div>
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: "Length (minutes):",
name: "learning_event.length"
}, {
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: "Week:",
name: "learning_event.week_fk",
type: "select",
placeholder: "Select Week..."
},{
label: "Assessment:",
name: "assessment[].assessment_pk",
type: "select",
placeholder: "Select Assessments...",
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: true,
attr: {
size: 1
}
} ]
} );
editor.dependent('learning_event.unit_group_fk', 'program_data/get_weeks.php');
editor.dependent('learning_event.unit_group_fk', 'program_data/get_assessments.php');
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",
}, {
data: "learning_event.outline",
}, {
data: "learning_event.length",
}, {
data: "program_outcome",
render: "[, ].program_outcome"
}, {
data: "unit_group.unit_group"
}, {
data: "week.week_full_name"
}, {
data: "assessment.assessment",
render: "[, ].assessment"
}, {
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:
In what way does it not work? Does it not make the second Ajax request, or is there an error or something else? If you could link to a test case showing the issue, that would be really useful.
Thanks,
Allan
The problem was with the script that populates the assessment select. I was sending data that needed to be used sub queries in that script to get the correct data. Fixed!