The CreatorCon Call for Content is officially open! Get started here.

How to clear all values on a CI form?

gunishi
Tera Guru

Hi all, 

 

Is there a way to clear all values on a CI form?

 

I could put them all in an array and loop through them, but as I have a lot of variables, I was wondering if there is a more efficient way to do this or if the array is the best way to go?

 

Any help would be much appreciated. 

 

Kind regards, 

G

1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage

Hello @gunishi 

 

var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
    g_form.setValue(fields[x], "");
}

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

View solution in original post

3 REPLIES 3

Samaksh Wani
Giga Sage

Hello @gunishi 

 

var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
    g_form.setValue(fields[x], "");
}

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

Hi @Samaksh Wani 

 

Thank you so much for your help. This has helped me no end!

 

Kind regards, 

G

@Samaksh Wani 

 

I tried this coding and it worked, but i want to refresh a catalog item if lets say the request type changes.  So i did an onchange script so that when the field request type is changed i excute the code:  

var fields = g_form.getEditableFields();  
for (var x = 0; x < fields.length; x++) {
    g_form.setValue(fields[x], "");
}


but what is happening is yes all the values on the catalog item is cleared and if I go back to the request type field to start to fill out the catalog item again it just keeps resetting the catalog item. Basically I want to be completing a catalog item and lets say i was 3/4 completed and then decide to change the type and enter a different value in the request type and a whole new set of fields are presented. I start to answer those questions and then decide to go back to the value in the request field that I had to begin with and when I do all the values still remain. Is there a way that I can clear out or 'reset' the whole catalog item?