How to find text of select box with given any option on presubmit event?
How to find text of select box with given any option on presubmit event?

Hi,
My datatables editor form has a select box 'sBox' and I am listening to its 'change' event like below
$('select', editor.node('sBox')).on('change', function () {
console.log('on change -> '+editor.get('sBox'));
//The console prints value of the item I select.
});
I am listening to the presubmit event like below:
editor.on('preSubmit', function (e, o, action) {
console.log('on presubmit -> '+editor.get('sBox'));
//The console prints value of the item I select.
editor.create(false).set('personName', editor.field('sBox').input().find({option:selected}).text());
//where person name is a hidden field defined on editor.
}
However, the personName here does not correspond to the value that was selected.
The personName value corresponds to the value that was initialized at the time of creating the editor.
I tried using the below code to get the text of value that was selected after the 'change' event. But I get the same results.
editor.create(false).set('personName', editor.field('sBox').input().find('option[value="'+editor.get('sBox')+'"]').text());
Is there something that I am missing?
Answers
I put in more console.log statements in this code, and see that
editor.field('sBox').input().find('option[value="'+editor.get('sBox')+'"]').text()
pulls out the correct text against the given option value, but the problem is that it is not being set to the personName hidden field.
I tried appending submit() at the end like below, but still does not work.
editor.set('personName', editor.field('sBox').input().find('option[value="'+editor.get('sBox')+'"]').text()).submit();
I tried putting the below option on editor definition, but no difference:
formOptions : {
main : {
submit : 'all'
}
},
This answer worked for me:
https://datatables.net/forums/discussion/27039/editor-how-to-pass-select-label-to-update-method#Comment_73505