Hi, need help on my requirements where in I need to set fields on my form as req

Hi, need help on my requirements where in I need to set fields on my form as required. I have read that advance form utilities will do the trick but however I'm getting error while trying my code. Please see me code below and let me know if I mis something.

if (window.FormAPI.getValue("button1").id=="Create")
{
window.FormAPI.setRequired("text4",true);
window.FormAPI.setRequired("text6",true);
window.FormAPI.setRequired("text9",true);
window.FormAPI.setRequired("text10",true);
window.FormAPI.setRequired("radio22",true);
window.FormAPI.setRequired("dropdown14",true);
}
else
{window.FormAPI.hide("hidden24");}


TIA!...

OriginalPostID-120790

OriginalPostID-120790

  Discussion posts and replies are publicly visible

  • Hi subhankarb, its an exceptional error. Give me a min. I'll post it..thanks!
  • Hi subhankarb, please see attached for the error encountered.

  • Hi Jessica, kindly validate if you have used the import script on load of the form.
    Create a event rule of type load and define with the below value.
    importScript("/plugins/servlet/FormsExt.js");

    you may also like to modify your code in the else part by just {}.Since the field you are trying to hide using the script is already a hidden field.
  • it work subhankarb! One last question, if fields were set a required then the form shouldn't submit right?
  • Hi Jessica, You can not stop the form onsubmit event though we are setting the fields as required. You can go for individual field level validation to retuen true or return false based on button selection.This will not allow the form to sumbit unless all the fields are returning true using js validation.
  • I use the following JS code. I create a field on the form with the ID "txtValidateForm" (which is hidden onLoad), submit button as "btnSubmit" and cancel button as "btnCancel". onLoad_Form() is called on the form load, required fields each call the validation function as: Return ValidateNotNull("fieldName"); which decides if validation should continue or if it should be bypassed - based on the value set in txtValidateForm by either the Submit or Cancel button just pressed. Cancel sets the txtValidateForm field to No, bypassing validation, where Submit sets the field to Yes which forces each required field to validate. I add a "*" just before each required field name - you can also add an image of a red "*" in there for the same display as a physically required field.

    function onLoad_Form()
    {
              window.FormAPI.hide("txtValidateForm");
              onLoadCancelButton("btnCancel");
              onLoadSubmitButton("btnSubmit");
    }

    function ValidateNotNull(fieldName)
    {
              if(window.FormAPI.getValue("txtValidateForm").id == "YES") return true;

              var data = window.FormAPI.getValue(fieldName).id;
              if(data != "") return true;
              else
              {
                        asi.alert("Fields are Required!");
                        return false;
              }
    }

    function onLoadCancelButton(btnCancel){

    var buttonConfig = window.Build.util.getComponentContainer(btnCancel,window.FormDesigner.runtimeNamespace);

    var clickFunction = function(){
    window.FormAPI.setValue("txtValidateForm","NO");
    };

    buttonConfig[0].firstChild.onkeydown = clickFunction;
    buttonConfig[0].firstChild.onmousedown = clickFunction;
    }


    function onLoadSubmitButton(btnSubmit){

    var buttonConfig = window.Build.util.getComponentContainer(btnSubmit,window.FormDesigner.runtimeNamespace);

    var clickFunction = function(){
    window.FormAPI.setValue("txtValidateForm","YES");
    };

    buttonConfig[0].firstChild.onkeydown = clickFunction;
    buttonConfig[0].firstChild.onmousedown = clickFunction;
    }