Need help with code that checkes to make sure all required fields are not "0" | Community
Skip to main content
February 7, 2022

Need help with code that checkes to make sure all required fields are not "0"

  • February 7, 2022
  • 1 reply
  • 1101 views

I have a javascript code that I created to check for any fields that are required and have a value of "0" to display an alert, which I made for Acrobat form, I need help converting for AEM, and was hoping someone could help me out?

 

Here is the code I have:

pmp.Page9.#subform[2].check_form::mouseDown - (JavaScript, client) var emptyFields = []; for (var i=0; i<this.numFields; i++) { var f= this.getField(this.getNthFieldName(i)); if (f.type!="button" && f.required ) { if (f.valueAsString==f.defaultValue) emptyFields.push(f.name); } } if (emptyFields.length>0) { app.alert("**The first number indicates the Objective number** \n \n You have a zero rating in the Measuring Success section for the following ratings:\n\n" + emptyFields.join("\n")); } else { app.alert("All fields have been filled out successfully, and no errors were found.", 3) }

I was hoping to get some pointers to help me learn.

All of the drop down fields default value is "0", and I have another script, that I am trying to work on as well to convert, which will make the fields I need set to required, if this field in not empty, since we have 13 sets of questions, which don't all get used all of the time.

So here is the code that I have for the field that sets the required presence:

if(pmp.Page1.object1.kpi1.value == null) {// Field is empty, other fields not required pmp.Page1.object1.Table1.Row1.ratingbox1_1.presence = "optional"; pmp.Page1.object1.Table1.Row1.ratingbox1_2.presence = "optional"; pmp.Page1.object1.Table1.Row1.ratingbox1_3.presence = "optional"; pmp.Page1.object1.Table1.Row1.ratingbox1_4.presence = "optional"; pmp.Page1.object1.Table1.Row1.ratingbox1_5.presence = "optional"; } else {// Field has data, other feilds required pmp.Page1.object1.Table1.Row1.ratingbox1_1.presence = "required"; pmp.Page1.object1.Table1.Row1.ratingbox1_2.presence = "required"; pmp.Page1.object1.Table1.Row1.ratingbox1_3.presence = "required"; pmp.Page1.object1.Table1.Row1.ratingbox1_4.presence = "required"; pmp.Page1.object1.Table1.Row1.ratingbox1_5.presence = "required"; }

I have been trying to modify it for AEM, but still no luck with the 2nd piece of code either.

Can someone please help me out?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Mayank_Tiwari
Adobe Employee
Adobe Employee
February 8, 2022

Why you are using the .presence? 

Presence is used to set the object’s visibility. Also, presence can only be set to these values: 

Reference_Syntax.presence = "visible | invisible | hidden | inactive"

Not the ones you are using.

Also, .value won't work in JavaScript. you need to use .rawValue, as below:

 

pmp.Page1.object1.kpi1.rawValue == null

 

 

You need to use following JavaScript to set the field as required:

 

Reference_Syntax.mandatory = "error";  

or

Reference_Syntax.validate.nullTest = "error";

Script reference: https://help.adobe.com/en_US/AEMForms/6.1/DesignerScriptingBasics/WS92d06802c76abadb57cc1b6e12a92343946-7ff8.2.html

 

February 8, 2022

Thank you for your help, I thought i was using the right code, just looking at the dropdown values available under presence, that's why i was using that, so thank you for your help with that.  What about the first part of code?  When i click on the button it displays the 2nd alert.  Will is display correctly once I fix the second piece of code?