Set editor field instance type on preOpen ?
Set editor field instance type on preOpen ?
As a follow up to my last question https://datatables.net/forums/discussion/38229/custom-validation-on-the-fly#latest I have the validation working great.
My icing on this particular cake would be to show a field type pertinent to the data in the editor instance.
At the moment, the field is always a text field, which works, but if possible, i would like to show a checkbox if the data type has been set to boolean, or a select list, or whatever.
I have been looking at preOpen and modifier, and by this method, I can set the field instance label, value etc, as per https://editor.datatables.net/reference/api/ but I can't see a way to set the field instance type
eg
editor.on( 'preOpen', function ( e ) {
var mode = editor.mode(); // Gets editor mode, (create, edit, remove)
var modifier = editor.modifier(); // Gets the selected row of the table
if ( modifier ) {
// Get data for this row
var data = table.row( modifier ).data();
var opttype = data.refglobaloptions.OptionType;
console.log( opttype );
var optval = editor.field('refglobaloptions.OptionValue');
if (opttype == 1) {
optval
.label('hello');
}
....
}
} );
This question has accepted answers - jump to:
Answers
You can't dynamically change the field's type after initialisation. You'd need to remove the field (
clear()
) and then add a new one of the new type (add()
).Allan
Great,
here is a simplified version of what i will do, no errors, but the field value does not appear in the editor field instance
Yes, you'd need to read the value and then set it when you add the new field. It won't (currently) automatically pick up the value. I might change that behaviour!
Allan
cool, easy enough.
Thanks again.