Regex + Repeats

Hello, I'm not really sure how to even ask this. I have a situation where I need to paste multiple people's information into a form but only need a single phone number. I have it set up where I can choose the number of passengers, then have it repeat my entry fields based on that information. With checkboxes I can select or deselect (if both people have phone numbers in their data) so only select a single phone number for entry.

But I'm wondering if there is a way to determine if no phone box is checked so I can toggle an error/box to enter a phone number.

Here's what I have so far:

Data that will parse:

Phone
+41221545544
First Name
TestFirst
Last Name
TestLast

Snippet:

{note}Number of People: {formmenu: name=entries; cols=5; values={=seq(1, 9)}; default=2}
{repeat: for entry in seq(1, entries); locals=reps; trim=right}
Person {=entry}
{formparagraph: name=data; cols=80; rows=3}
Phone {phone=extractregex(data, "Phone\s(.)")}{=phone}
First Name {firstname=extractregex(data, "First Name\s(.
)")}{=firstname}
Last Name {lastname=extractregex(data, "Last Name\s(.*)")}{=lastname}
{endrepeat}{endnote}{repeat: for entry in seq(1, entries); trim=right}{note}
Person {=entry}
{endnote}{formtoggle: default=yes}-{=reps[entry]["lastname"]}/{=reps[entry]["firstname"]}{key:enter}{endformtoggle}
{endrepeat}{note}
Need to know if there is no phone selected (Checked) so I can have toggle an error/box to enter in a phone number
{endnote}{repeat: for entry in seq(1, entries); trim=right}{note}
{endnote}{formtoggle: default=yes}Phone {=reps[entry]["phone"]}{key:enter}{endformtoggle}{endrepeat}

@Kevin_Roberts
I made several changes to the snippet to optimize and tried to get your use case worked out.

I was checking if phonenos is selected to show a new field

Also made regex match for phone number in a catch to set a default over make it as a error.

I changed to second repeat to use reps directly for ease.

Also I change the regex to match using .+ over .*. The later is greedy while matching.

{note}Number of People: {formmenu: name=entries; cols=5; values={=seq(1, 9)}; default=2}
{repeat: for entry in seq(1, entries); locals=reps; trim=right}
Person {=entry}
{formparagraph: name=data; cols=80; rows=3; default=
First Name
Test1 First
Last Name
Test2 Last}
Phone {phone=catch(extractregex(data, "Phone\s(.+)"),"")}{=phone}
First Name {firstname=extractregex(data, "First Name\s(.+)")}{=firstname}
Last Name {lastname=extractregex(data, "Last Name\s(.+)")}{=lastname}
{endrepeat}{endnote}{repeat: for entry in seq(1, entries); trim=right}{note}
Person {=entry}
{endnote}{formtoggle: default=yes}-{=reps[entry]["lastname"]}/{=reps[entry]["firstname"]}{key: enter}{endformtoggle}
{endrepeat}{repeat: for rep in reps; trim=right; locals=phonenos}{note}
{endnote}{if: rep["phone"]<>""}{formtoggle: default=yes; name=selected}Phone {=rep["phone"]}{key: enter}{endformtoggle}{endif}{endrepeat}
{if: count(filter(phonenos, pno -> pno["rep"]["phone"] <> "" and pno["selected"]))==0}Phone:{formtext: name=customphone}{key: enter}{endif}

1 Like

Very helpful. Thank you!

1 Like