Within my form, there is a table labeled as table0 which contains various dijit form controls. Additionally, there are buttons for adding and removing tables where each new table is assigned an ID incremented by 1. For instance, the first click on the add button will result in table1, the second click will create table2, and so on. Clicking on the remove button will remove the last table.
Below is the function for adding a new table:
function getNewTable() {
dojo.query('#addTable').onclick(function() {
var tableNode = dojo.byId('table'+count);
count++;
dojo.xhrGet({url: 'addTable.html',
handleAs: "text",
preventCache: true,
content:{fieldId:count} ,
load: function(data) {
var newTable = dojo.place(data, tableNode, 'after');
dojo.parser.parse(newTable);
},
error: function(error) {
var newTable = dojo.place("AJAX error: " + error, deductNode, 'after');
dojo.parser.parse(newTable);
}
});
});
}
The remove function is as follows:
function removetable() {
dojo.query('#removeTable').onclick(function() {
if (count != 0) {
var tableNode = dojo.byId('table'+count);
count--;
dojo.xhrGet({url: 'removeTable.html',
handleAs: "text",
preventCache: true,
content: {fieldId:count},
load: function(data) {
dojo.destroy(tableNode);
},
error: function(error) {
var newTable = dojo.place("AJAX error: " + error, tableNode, 'after');
dojo.parser.parse(newTable);
}
});
}
});
}
The count variable is declared globally.
Although the functions are functioning correctly, I am encountering an issue where adding a new table node after removing one will prevent the execution of dojo.parser.parse(newTable) for the node at that specific index.
I have debugged the code and all references seem to be correct. Everything works smoothly unless a node with a destroyed ID is placed.
For example, after clicking add, table1 is created and successfully parsed by dojo. Subsequently, clicking remove will delete table1 without any hitches. However, clicking add again to create table1 will not trigger dojo to parse the node.
Could I potentially be making a mistake somewhere?