Editor in field type datatable
Editor in field type datatable
Event based I am filling and opening an Editor instance with values retrieved from a content managment system. All of this works fine.
My issue is that the Editor instance I set and open programmatically does not behave the same as an Editor instance in field type "datatable" should. It should fall back to the parent Editor when closed and the record edited should be selected in the embedded data table. The programmatically opened Editor just closes everything when closed and also closes the parent Editor which it shouldn't. What do I need to change to make it work?
Here is my code. "vatQaEditor" is the embedded Editor in field type "datatable". "ctrPSCEditor" is the parent Editor.
ctrPSCEditor
.on('opened', function(e, type, action) {
var self = this;
$( self.field('vat_result.vat_subcategory_id').input() ).change( function() {
if ( self.field("vat_qa[].id").dt().rows().count() < 1 ) {
if ( self.val('vat_result.vat_subcategory_id') > 0 ) {
//read initial question and open the qa Editor
$.ajax({
type: "POST",
url: 'actions.php?action=getQaEditorValues',
data: {
vatSubcategoryId: self.val("vat_result.vat_subcategory_id"),
vatNumberCurrent: "" //this is the first one!
},
dataType: "json",
success: function (d) {
if ( d.vat_question === "no question found" ) {
return;
}
vatQaEditor.field('vat_qa.vat_option').update(d.vat_options_arr);
vatQaEditor
// .title($.fn.dataTable.Editor.defaults.i18n.create.title)
.title(lang === 'de' ? 'PSC USt.-Frage ' + d.vat_number + ' beantworten' :
'Answer PSC VAT question ' + d.vat_number)
.buttons( {
label: $.fn.dataTable.Editor.defaults.i18n.create.submit,
className: 'btn-showall-color',
fn: function () {
this.submit();
}
} )
.create()
.set( { 'vat_qa.vat_question': d.vat_question,
'vat_qa.vat_hint': d.vat_hint,
'vat_qa.number': d.vat_number } );
}
});
}
}
});
This question has an accepted answers - jump to answer
Answers
Think you are the first one to try this .
Use:
to let Editor know you want it to do a nested edit.
Allan
I love easy fixes, Allan! Many thanks!!
I tested it thoroughly and it works like a charm!