• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Hidden Required fields - existing script isn't working.

New Here ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

Hello All!

I have a script that is designed to scan through the form when the users submits it and make any hidden required fields un-required. However, recently after a change to the default profile (I think this was the inciting incident, I'm not entirely sure), the user has to press the submit button twice in order for the script to work. 

I have absolutely no idea what's causing this, I poured over it all day, but can't figure it out. Any help would be greatly appreciated! Relevent code linked below:

-----------

function validateForm() {
	fixNullTest( xfa.form.form1.formPage );
	console.log("after fix null test");
	var validationReturn = !ValidationHTML.setFocusToRequired(xfa.form.form1.formPage, null, true).bool;
	console.log("after validationHTML")
	console.log("validation return: " + validationReturn)
	return validationReturn;
	
}//function

// this is called by validate form to turn off the required attributes for fields
// that are hidden
function fixNullTest( oNode ) {
	if ( oNode.presence == "hidden" || oNode.presence == "invisible" )
	{
		turnOffNullTest( oNode );
	}//if
	else 
	{
		for(var i=0; i<oNode.nodes.length; i++) 
		{
			var oChildNode = oNode.nodes.item(i);
			if ( oChildNode.className == "subform" || oChildNode.className == "exclGroup" )
			{
				fixNullTest( oChildNode );
			}//if
			else if ( oChildNode.className == "field" && (oChildNode.presence == "hidden" || oChildNode.presence == "invisible"))
			{
				turnOffNullTest( oChildNode );
			}//else if
		}//for
	}//else
}//func

function turnOffNullTest( oNode ) 
{
	//console.log("begining of turn off null test for: " + oNode.className);
	
	switch( oNode.className ) 
	{
		case "exclGroup":
			oNode.validate.nullTest = "disabled";
		case "subform":
			for(var i=0; i<oNode.nodes.length; i++) 
			{
				var oChildNode = oNode.nodes.item(i);
				turnOffNullTest( oChildNode );
			}//for
			break;
		case "field":
			switch (oNode.ui.oneOfChild.className) 
			{
				case "checkButton":
				case "choiceList":
				case "dateTimeEdit":
				case "exclGroup":
				case "imageEdit":
				case "numericEdit":
				case "passwordEdit":
				case "textEdit":
				case "signature":
					oNode.presence = "visible";
					oNode.validate.nullTest = "disabled";
					oNode.presence = "hidden";
					//oNode.presence = "inactive";
					//console.log("field has actually been turned off");
					break;
				default:
					break;
					
			}//switch
			break;
	}//switch
	
	
}//func

 The code below this is used above, but I don't think the problem lies here. This code basically just makes the text red and sets focus, but the main issue is the form not submitting when visible fields are all completed.

//function to find required fields left empty and setting the focus on them after submit

function setFocusToRequired(oNode, found, base)
{
	//console.log("Hello.  In setFocusToRequired");
	if (found == null) 
	{
		found = {};	
	}//if	
	for(var i=0; i<oNode.nodes.length; i++) 
	{
		var oChildNode = oNode.nodes.item(i);
		if (oChildNode.className == "field" || oChildNode.className == "exclGroup")
		{
			if (oChildNode.validate.nullTest == "error" && (oChildNode.rawValue == "" || oChildNode.rawValue == null))
			{
				if (oNode.className == "area")
				{
					for (var n = oNode.index; n>=0; n--)
					{
						if (oNode.parent.nodes.item(n).className == "draw")
						{
							oNode.parent.nodes.item(n).font.fill.color.value = "255,0,0";
							break;
						}//if
					}//for
				} //if
				else if (oChildNode.className == "field")
				{
					oChildNode.caption.font.fill.color.value = "255,0,0";
				} //else if
				else 
				{
					for (var n = i; n>=0; n--)
					{
						if (oNode.nodes.item(n).className == "draw")
						{
							oNode.nodes.item(n).font.fill.color.value = "255,0,0";
							break;
						}//if
					}//for
				}//else
				if (found.field == null) 
				{
					found.field = oChildNode;
				}//if
				found.bool = true;
			} //if
			else 
			{
				if (oNode.className == "area")
				{
					for (var n = oNode.index; n>=0; n--)
					{
						if (oNode.parent.nodes.item(n).className == "draw")
						{
							oNode.parent.nodes.item(n).font.fill.color.value = "0,0,0";
							break;
						}//if
					}//for
				} //if
				else if (oChildNode.className == "field")
				{
					oChildNode.caption.font.fill.color.value = "0,0,0";
				}//else if
				else 
				{
					for (var n = i; n>=0; n--)
					{
						if (oNode.nodes.item(n).className == "draw")
						{
							oNode.nodes.item(n).font.fill.color.value = "0,0,0";
							break;
						}//if
					}//for
				}//else
			}//else
		}//if
	
		if (oChildNode.className == "subform" || oChildNode.className == "area" || oChildNode.className == "exclGroup")
		{
			setFocusToRequired(oChildNode, found, false);
		}//if
	}//for
	if (base)
	{
		if (found.field != null) 
		{
			xfa.host.messageBox("At least one required field was not completed correctly. Please fill in all required fields and try to submit again.");
			xfa.host.setFocus(found.field.somExpression);
		}//if
	}//if
	return found;
}
TOPICS
General troubleshooting , JavaScript

Views

474

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

There's a forum for XFA based forms you can use. This forum is more for AcroForms. 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-forms/ct-p/adobe-experienc...

 

Anyway. Are there any errors reported in the Javascript console?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

LATEST

Ah, my bad! I still had this forum saved (part of the changes that we're making is to switch off of Acro over to XFA, it's been a process!). 

 

None 😞 I even tried wrapping several different segments in try-catches and nothing tripped them. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines