Clear all field values on the form when one field value changes

User209405
Mega Expert

I have 15 variables on a catalog item. Each field is dependent on previous selection which is controlled by UI policy. The issue is when user reselects any previous variables without removing the current selected values, the variable that should have been hidden still shows.

I saw the suggestion of using  g_for­m.c­lea­rVa­lue­() or g_form.clearoptions in other forums but not sure how to approach it.

What would be the best way to reset all fields value on change? Creating 15 scripts on all UI policies will be crazy. Would creating a UI client script achieve this if so which g_form_ to use.

Thanks

 

1 ACCEPTED SOLUTION

Virendra Mali
Mega Expert

Hello,

Please write a client script onchange type and please select a variable on which you want to run a clear field

using g_form.clearValue("") .

You also put a condition like

if(g_form.getValue("variable name")=="matches string"){

 

g_form.clearValue("variable name")

}

 

Please mark my answer as correct and helpful

Regards,

Virendra

 

View solution in original post

4 REPLIES 4

Ankush Jangle1
Kilo Guru

Hello,

 

you can used this syntax to clear the value

g_form.clearValue('fru_last_name'); like that you can use

 

 

 

Please MArk it as Correct/Helpful if it hleps you

Virendra Mali
Mega Expert

Hello,

Please write a client script onchange type and please select a variable on which you want to run a clear field

using g_form.clearValue("") .

You also put a condition like

if(g_form.getValue("variable name")=="matches string"){

 

g_form.clearValue("variable name")

}

 

Please mark my answer as correct and helpful

Regards,

Virendra

 

Hitoshi Ozawa
Giga Sage
Giga Sage

Something like below will clear all fields displayed below the changed field while not changing the current or the fields displayed above the current field.

    var allFields = g_form.nameMap;
    for (var i = 0; i < allFields.length; i++) {
        if (control.id == g_form.resolveNameMap(allFields[i].prettyName)) {
            for (var j = i + 1; j < allFields.length; j++) {
                g_form.clearValue(allFields[j].prettyName);
            }
        }

Harshal Gawali
Giga Guru

Hello,

Try below script in UI policy.

var arry = [variable1, variable2]; //keep on adding all the variable names

for(var i =0; i < arry.length; i++)

{

        g_form.clearValue(arry[i]);

}

 

Regards,

Harshal.