Remove and add part of editor form by javascript on select change
Remove and add part of editor form by javascript on select change
Hi..
I have a case where,
Default view of editor form has
- 5 static fields (whose name I know) + 1 select box
- 2 Dynamically generated input boxes (generated by Ajax response)
editor.add({
'label' : ctf.field_name,
'name' : name
});
Now when user changes the select option... I want the above 2 dynamic fields to disappear and instead new dynamic fields (specific to selected option be shown)
The catch here is that, I dont know the Dynamic fieldNames so that I cant just use editor.clear(name);
I am trying to do something like this...
getCommodityTransactionFieldListForSauda = function(commodityId) {
$.ajax({
type: 'GET',
url: base_url + 'api/commoditytransactionfield?transaction=Sauda&commodityId=' + commodityId,
dataType: "json",
async: true,
success: function(cTFList){
$.each(cTFList['data'], function(index, ctf) {
var name = 'ctf.' + ctf.commodity_transaction_field_id;
if (typeof editor.field(name) != 'undefined') {
editor.clear(name);
}
if (ctf.commodity_id == commodityId) {
editor.add({
'label' : ctf.field_name,
'name' : name
});
//editor.field(name).update(ctf.field_value);
}
});
},
error: function() {
alert("System error. Please try again later.");
}
});
}
Kindly suggest a solultion for this...
I am thinking in terms of
- adding a parent DIV with dynamic fields as children of parent div and when the select option is changed remove the parent div entirely and add new parent div with new children
But I am not sure how that can be achieved....
This question has an accepted answers - jump to answer
Answers
I don't understand why you don't know the names of the fields you want to remove? Can you not store them somewhere when they were added so you know which ones to remove in future?
Allan
Hi allan,
I can store it somewhere... but I want it to be dynamic
Admin selects what data to ask the user to fill in
Ex:
for option A :- ask for 3 fields
for option B :- ask for 5 fields
and admin can use any name for the fields depending on the select options provided...
I am trying to make a very dynamic app where admin can almost decide what data to ask the user.....
Absolutely - but you need to know what to ask for. So when you ask for 3 or 5 fields, or whatever, store that information somewhere, a Javascript variable for example, and then use that to build the columns.
Allan
Hi Allan
Thanks a lot for your quick reply,... I tried out your way and it works like a charm..
thanks a lot for the idea..!!