How to disable all the mandatory fields using single function/command.

balaji_prusty1
Giga Guru

Hi All;

In change form   we have lots of mandatory fields depends on the state/type of change. When user need to cancel the change he/she not to ask to fill the mandatory fields depends in which state he/she cancelling.

I can use g_form.setMandatory("FiledName" , false). But again I need to write code for all the mandatory fields (its around 30+) .

Is there any other way to remove/disable all the mandatory fields using single line code.

Thanks in Advance.

Balaji Prusty.

1 ACCEPTED SOLUTION

I am not getting the Close the loop / Answered   under Action....I was looking for this option.



All my previous threads are still open due to this...not sure what/whom need to contact to get this.


View solution in original post

24 REPLIES 24

zica
Giga Guru

Balaji,



Use thefunction above to ignore all o them, force to make the close note mandatory with something like close_note.mandatory = true.


Hi Zic;



It Not works if put like this.



g_form.checkMandatory = false;

close_notes.mandatory = true;


xiaix
Tera Guru

For me, it doesn't seem like anyone understands your question.  You asked, "Is there any other way to remove/disable all the mandatory fields using single line code."

 

Well, maybe not "one line", but one simple for() loop.

for (var i = 0; i < g_form.elements.length; i++)
{
    var el = g_form.elements[i];
    var fieldName = el.fieldName;
    g_form.setMandatory(fieldName, false);
}

Hi Davidd, this did not work for me.

I also tried to disable specific fields like g_form.setMandatory(category, false), but that appears to do nothing.

pawan k singh
Tera Guru

You can try below code on UI action. It will work.

function callClientScript() {
    //Client Script
    var arr = g_form.getMissingFields();
    for (var x = 0; x < arr.length; x++) {
        g_form.setMandatory(arr[x], false);
        alert("Following fields are set Non Mandatory: " + arr[x]);
    }
    gsftSubmit(null, g_form.getFormElement(), 'update_to_p1'); // UI action name
}

if (typeof window == 'undefined')
    callServerScript();

function serverScript() {
    // Server Script
    current.update();
    action.setRedirectURL(current);
}

find_real_file.png

Please mark answer helpful if it helped.
Regards
Pawan K Singh