`Problem:
We have built a feature in DataTables that allows users to copy an existing record. This feature lets users edit only the required fields (approximately 20+ fields) assuming that the majority of the data remains the same. However, this requires the user to change at least 4 to 5 dropdown fields at a minimum on the “copied” record.
The copy function works fine, but after a successful copy, the dropdown change events are being triggered twice. This means each field that we change takes twice as long to process. You can imagine if there are 5 or 6 fields that require changes, this can take more than an acceptable amount of time.
Example Change Event Code:
Change Event 1: Selection of “entity” field triggering data fetching for “function” field
$(document).on('change', '#DTE_Field_entity', function (e) {
var entity = $(this).val();
if (entity) {
clearErrorMessage('entity');
updateFunctionDropdown(entity);
}
});`
Change Event 2: Selection of “function” field triggering other subsequent change events
$(document).on('change', '#DTE_Field_function', function (e) {
var department = $(this).val();
if (department) {
clearErrorMessage('function');
updateFunctionalRoleDropdown(department);
updateOfficeLocationDropdown(department);
}
});
Copy Feature Code:
`
editor.inlineCreate('start', {
cancelTrigger: 3,
cancelHtml: '<i class="fa fa-times"/>',
submitTrigger: 2,
submitHtml: '<i class="fa fa-floppy-o"/>'
});
var tr = $(this).closest("tr");
var row = table.row(`#${$(tr).attr("id")}`).data();
var fields = editor.displayed();
for (var i = 0; i < fields.length; i++) {
editor.field(fields[i]).val(row[fields[i]]);
}`
Question:
Is there a way to prevent the change events from being triggered twice? Is there an alternative to the editor.inlineCreate function that might help avoid this issue?
Any guidance on the above would be greatly appreciated.`your text“
srinu k is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.