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

Create a toggle button

jesterize
Tera Contributor

We are attempting to create a UI Action button that toggles all fields to be editable on what they currently are set. We have the code:

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

But what is the best method to reverse it? Create another UI Action that just undoes what was already done?

2 REPLIES 2

Elijah Aromola
Mega Sage

You could make another UI action. You could also make a hidden field that stores a true/false value. Use that as the toggle for the one UI action. 

siva_
Giga Guru

You can have a flag and have a function on button click checking the flag value and behave accordingly something like 

on Click : setFields()

function setFields(){

if(flag){

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

}

else{

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

}}

 

Hope that helps 

 

Mark the response as correct if that really helps

Thanks,

Siva