Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Split Field Name based on Regex Query

Engaged ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

Is it possible to split a field name that was declared using a regex query? I'm trying to find the field name then split the field name to extract the number to then use that to hide/show form elements.

 

The debugger gets held up on card.split and tells me it's not a function. I tried several things to no avail.

 

//set all module selection test regex
	for (var i = 0; i < this.numFields; i++) {
		var fname = this.getNthFieldName(i);
		var f = this.getField(fname);
		var mods = /modules-\den/;
		if (f.name.match(mods)) {
			f.setAction("MouseUp",
				'for (var i = 0; i < this.numFields; i++) {\n' +
					'var fname = this.getNthFieldName(i);\n' +
					'var f = this.getField(fname);\n' +
					'var mNum = event.targetName;\n' +
					'var card = /card\\d/;\n' +
					'var cardT = /card-\\d/;\n' +
					'var reset = /reset\\d/;\n' +
					'var gfx = /enclosure\\dm/;\n' +
					'var ary8 = "12345678";\n' +
					'var mSplit = mNum.split("-");\n' +
					'var mName0 = mSplit[0];\n' +
					'var mName1 = mSplit[1];\n' +
					'var sMod = mName1.split("e");\n' +
					'var modName = sMod[0];\n' +
					'var cSplit = card.split("d");\n' +
					'var cName0 = cSplit[0];\n' +
					'var cName1 = cSplit[1];\n' +
					'var cTSplit = cardT.split("-");\n' +
					'var cTName0 = cTSplit[0];\n' +
					'var cTName1 = cTSplit[1];\n' +
					'var rSplit = reset.split("t");\n' +
					'var rName0 = rSplit[0];\n' +
					'var rName1 = rSplit[1];\n' +
					'var gSplit = gfx.split("e");\n' +
					'var gName0 = gSplit[0];\n' +
					'var gName1 = gSplit[1];\n' +
					'var gnSplit = gName1.split("m");\n' +
					'var gName = gnSplit[0];\n' +
					'if(modName.value == "2") {\n' +
						'sReset.display = display.visible;\n' +
						'if(f.name.match(card) && cName1.value == ary8[0,1] && rname1.value == ary8[0,1]) {\n' +
							'card.display = display.visible;\n' +
							'cardT.display = display.visible;\n' +
							'reset.display = display.visible;\n' +
						'}\n' +
						'else if(f.name.match(card) && cName1.value == ary8[2-7] && rname1.value == ary8[2-7]) {\n' +
							'card.display = display.hidden;\n' +
							'cardT.display = display.hidden;\n' +
							'reset.display = display.hidden;\n' +
						'}\n' +
						'if(f.name.match(gfx) && gName.value == ary8[0]) {\n' +
							'gfx.display = display.visible;\n' +
						'}\n' +
						'else if(f.name.match(gfx) && gName.value == ary8[1-3]) {\n' +
							'gfx.display = display.hidden;\n' +
						'}\n' +
					'}\n' +
					'else if(modName.value == "4") {\n' +
						'sReset.display = display.visible;\n' +
						'if(f.name.match(card) && cName1.value == ary8[0-3] && rname1.value == ary8[0-3]) {\n' +
							'card.display = display.visible;\n' +
							'cardT.display = display.visible;\n' +
							'reset.display = display.visible;\n' +
						'}\n' +
						'else if(f.name.match(card) && cName1.value == ary8[4-7] && rname1.value == ary8[4-7]) {\n' +
							'card.display = display.hidden;\n' +
							'cardT.display = display.hidden;\n' +
							'reset.display = display.hidden;\n' +
						'}\n' +
						'if(f.name.match(gfx) && gName.value == ary8[1]) {\n' +
							'gfx.display = display.visible;\n' +
						'}\n' +
						'else if(f.name.match(gfx) && gName.value == ary8[0,2,3]) {\n' +
							'gfx.display = display.hidden;\n' +
						'}\n' +
					'}\n' +
					'else if(modName.value == "6") {\n' +
						'sReset.display = display.visible;\n' +
						'if(f.name.match(card) && cName1.value == ary8[0-5] && rname1.value == ary8[0-5]) {\n' +
							'card.display = display.visible;\n' +
							'cardT.display = display.visible;\n' +
							'reset.display = display.visible;\n' +
						'}\n' +
						'else if(f.name.match(card) && cName1.value == ary8[6,7] && rname1.value == ary8[6,7]) {\n' +
							'card.display = display.hidden;\n' +
							'cardT.display = display.hidden;\n' +
							'reset.display = display.hidden;\n' +
						'}\n' +
						'if(f.name.match(gfx) && gName.value == ary8[2]) {\n' +
							'gfx.display = display.visible;\n' +
						'}\n' +
						'else if(f.name.match(gfx) && gName.value == ary8[0,1,3]) {\n' +
							'gfx.display = display.hidden;\n' +
						'}\n' +
					'}\n' +
					'else if(modName.value == "8") {\n' +
						'sReset.display = display.visible;\n' +
						'if(f.name.match(card) && cName1.value == ary8[0-7] && rname1.value == ary8[0-7]) {\n' +
							'card.display = display.visible;\n' +
							'cardT.display = display.visible;\n' +
							'reset.display = display.visible;\n' +
						'}\n' +
						'if(f.name.match(gfx) && gName.value == ary8[3]) {\n' +
							'gfx.display = display.visible;\n' +
						'}\n' +
						'else if(f.name.match(gfx) && gName.value == ary8[0-2]) {\n' +
							'gfx.display = display.hidden;\n' +
						'}\n' +
					'}\n' +
				'}'
			);
		}
	}

 

TOPICS
Create PDFs, JavaScript, PDF forms

Views

436

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Jun 10, 2021 Jun 10, 2021
Your script is not readable.

Likes

Translate

Translate
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

May be better when you use a function at document level. And use the function at the button.

In a function the script is better readable and it is easier to debug the script.

Likes

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
Engaged ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

I'll give it a try!

Likes

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
Engaged ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

I tried it but no luck.

Prior to posting this, I felt like maybe I wasn't actually putting anything in the script to actually declare the fields other than defining the variables and queries, so I tried to add:

if(f.name.match(card) [ | | all other regex definitions that have split] ) { all split variables.

I was thinking maybe if the script was actually working to find the field names then adding the variables that split the field name when called it might work. It didn't and produced the same error, so it was removed.

My other thought is if I could get the regex query field names as a string, maybe it would then want to split the field name.

 

	this.addScript("modSel",
		'function modSelect() {\n' +
		'for (var i = 0; i < this.numFields; i++) {\n' +
			'var fname = this.getNthFieldName(i);\n' +
			'var f = this.getField(fname);\n' +
			'var mNum = event.targetName;\n' +
			'var card = /card\\d/;\n' +
			'var cardT = /card-\\d/;\n' +
			'var reset = /reset\\d/;\n' +
			'var gfx = /enclosure\\dm/;\n' +
			'var ary8 = "12345678";\n' +
			'var mSplit = mNum.split("-");\n' +
			'var mName0 = mSplit[0];\n' +
			'var mName1 = mSplit[1];\n' +
			'var sMod = mName1.split("e");\n' +
			'var modName = sMod[0];\n' +
			'var cSplit = card.split("d");\n' +
			'var cName0 = cSplit[0];\n' +
			'var cName1 = cSplit[1];\n' +
			'var cTSplit = cardT.split("-");\n' +
			'var cTName0 = cTSplit[0];\n' +
			'var cTName1 = cTSplit[1];\n' +
			'var rSplit = reset.split("t");\n' +
			'var rName0 = rSplit[0];\n' +
			'var rName1 = rSplit[1];\n' +
			'var gSplit = gfx.split("e");\n' +
			'var gName0 = gSplit[0];\n' +
			'var gName1 = gSplit[1];\n' +
			'var gnSplit = gName1.split("m");\n' +
			'var gName = gnSplit[0];\n' +
			'if(modName.value == "2") {\n' +
				'sReset.display = display.visible;\n' +
				'if(f.name.match(card) && cName1.value == ary8[0,1] && rname1.value == ary8[0,1]) {\n' +
					'card.display = display.visible;\n' +
					'cardT.display = display.visible;\n' +
					'reset.display = display.visible;\n' +
				'}\n' +
				'else if(f.name.match(card) && cName1.value == ary8[2-7] && rname1.value == ary8[2-7]) {\n' +
					'card.display = display.hidden;\n' +
					'cardT.display = display.hidden;\n' +
					'reset.display = display.hidden;\n' +
				'}\n' +
				'if(f.name.match(gfx) && gName.value == ary8[0]) {\n' +
					'gfx.display = display.visible;\n' +
				'}\n' +
				'else if(f.name.match(gfx) && gName.value == ary8[1-3]) {\n' +
					'gfx.display = display.hidden;\n' +
				'}\n' +
			'}\n' +
			'else if(modName.value == "4") {\n' +
				'sReset.display = display.visible;\n' +
				'if(f.name.match(card) && cName1.value == ary8[0-3] && rname1.value == ary8[0-3]) {\n' +
					'card.display = display.visible;\n' +
					'cardT.display = display.visible;\n' +
					'reset.display = display.visible;\n' +
				'}\n' +
				'else if(f.name.match(card) && cName1.value == ary8[4-7] && rname1.value == ary8[4-7]) {\n' +
					'card.display = display.hidden;\n' +
					'cardT.display = display.hidden;\n' +
					'reset.display = display.hidden;\n' +
				'}\n' +
				'if(f.name.match(gfx) && gName.value == ary8[1]) {\n' +
					'gfx.display = display.visible;\n' +
				'}\n' +
				'else if(f.name.match(gfx) && gName.value == ary8[0,2,3]) {\n' +
					'gfx.display = display.hidden;\n' +
				'}\n' +
			'}\n' +
			'else if(modName.value == "6") {\n' +
				'sReset.display = display.visible;\n' +
				'if(f.name.match(card) && cName1.value == ary8[0-5] && rname1.value == ary8[0-5]) {\n' +
					'card.display = display.visible;\n' +
					'cardT.display = display.visible;\n' +
					'reset.display = display.visible;\n' +
				'}\n' +
				'else if(f.name.match(card) && cName1.value == ary8[6,7] && rname1.value == ary8[6,7]) {\n' +
					'card.display = display.hidden;\n' +
					'cardT.display = display.hidden;\n' +
					'reset.display = display.hidden;\n' +
				'}\n' +
				'if(f.name.match(gfx) && gName.value == ary8[2]) {\n' +
					'gfx.display = display.visible;\n' +
				'}\n' +
				'else if(f.name.match(gfx) && gName.value == ary8[0,1,3]) {\n' +
					'gfx.display = display.hidden;\n' +
				'}\n' +
			'}\n' +
			'else if(modName.value == "8") {\n' +
				'sReset.display = display.visible;\n' +
				'if(f.name.match(card) && cName1.value == ary8[0-7] && rname1.value == ary8[0-7]) {\n' +
					'card.display = display.visible;\n' +
					'cardT.display = display.visible;\n' +
					'reset.display = display.visible;\n' +
				'}\n' +
				'if(f.name.match(gfx) && gName.value == ary8[3]) {\n' +
					'gfx.display = display.visible;\n' +
				'}\n' +
				'else if(f.name.match(gfx) && gName.value == ary8[0-2]) {\n' +
					'gfx.display = display.hidden;\n' +
				'}\n' +
			'}\n' +
		'}\n' +
		'}'
	)

	for (var i = 0; i < this.numFields; i++) {
		var fname = this.getNthFieldName(i);
		var f = this.getField(fname);
		var mods = /modules-\den/;
		if (f.name.match(mods)) {
			f.setAction("MouseUp", "modSelect();");
		}
	}

 

Likes

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
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

Your script is not readable.

Likes

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
Engaged ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

LATEST

I wound up changing field names and going an entirely different route and abandoning the split idea when I could just group them based on like field numbers I added to the end of the field name.

Likes

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
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

This is not valid JS notation for a string:

ary8[0,1]

Nor is this (for anything):

ary8[2-7]

The former will only return the first letter in the string. If you want to return a sub-string then use the substring method, like this:

ary8.substring(0,2);

This will return the first two characters of the string.

Likes

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