Add button Loop

Good morning,
I would like to know if there was a possibility to dynamically add text field buttons
What I would like is a button that allows you to add a text field and then asks you to add another, then another, then another etc... No limit as long as the button is checked Everytime.

A bit like this but dynamically, like a loop, knowing that each button and text field has a different tag:

{formtoggle: name=Toggle Field 0}{formtext: name=Text Field 0} add more ? : {formtoggle: name=Text Field +1; default=no}{formtext: name=Text Field 1}add more ? : {formtoggle: name=Text Field +2; default=no}{formtext: name=Text Field 2}add more ? : .....{endformtoggle}{endformtoggle}{endformtoggle}

Thank you in advance for your help !

Hi, and welcome to the forum! :slight_smile:

For the moment we don't have exactly what you want, but you could try something like this:

{note}Field count: {formmenu: 1;2;3;4;5;6; name=fields}{endnote}
{repeat: for i in seq(1, fields)}
Text field {=i}: {formtext}
{endrepeat}

Also keep your eyes out for our monthly update coming up next month. I don't want to spoil the surprise (and I can't 100% promise it), but we might have something pretty amazing in store related to what you're asking about.

Take a look at this :blush:

{yescount=count(filter(hello, (x) -> contains(x, "yes")))}
{repeat: 1 + yescount; locals=hello}{formtext}{note: preview=no}{formtoggle: name=toggle}{endnote}{if: toggle = no}{button: toggle = yes
; label=✍️}{else}{button: toggle = no
; label=↩️}{endif}
{endrepeat}

3 Likes

That perfect !

But how can we ensure that each text has its own label to then import?

The goal of this is that then I have further down the page the values ​​of all these texts which are imported: text1+text2+text3 etc...

I gave the formtext a name (so it can be used as a variable).
It automatically gets a value so the first one is hello[1].formtext, next one will be hello[2].formtext
and so on.

I show it as a repeat command here - try to fill out a couple of textboxes to see how it works.

{repeat: for x in hello}{=x.formtext}
{endrepeat}

{yescount=count(filter(hello, (x) -> contains(x, "yes")))}
{repeat: 1 + yescount; locals=hello}{formtext: name=formtext}{note: preview=no}{formtoggle: name=toggle}{endnote}{if: toggle = no}{button: toggle = yes
; label=✍️}{else}{button: toggle = no
; label=↩️}{endif}
{endrepeat}

To add to Benjamin's answer, if you wanted to sum up the values of all the text boxes you could do something like:

{repeat: for x in hello}{=x.formtext}
{endrepeat}

Summation: {=sum(map(hello, x -> x.formtext))}

{yescount=count(filter(hello, (x) -> contains(x, "yes")))}
{repeat: 1 + yescount; locals=hello}{formtext: name=formtext}{note: preview=no}{formtoggle: name=toggle}{endnote}{if: toggle = no}{button: toggle = yes
; label=✍️}{else}{button: toggle = no
; label=↩️}{endif}
{endrepeat}

1 Like

Good morning,

I have a problem again.
I struggled thanks to your previous answers.

However I can't do a loop on the IFs, putting "x" doesn't work, putting 1 works but it only takes the first value (which is logical).

Except that if we make 2x the TBD choice and put a value, I would like it to separate like with the Formula.

I have formatted the text for you but you should know that normally I have several ifs which change depending on the price, so it is not only for TBD

If you have an idea ?

{note}{yescount=count(filter(countsub, (x) -> contains(x, "yes")))}{repeat: 1 + yescount; locals=countsub}
{formmenu: default=5€; 10€; 20€; TBD; name=choice}
{if: choice = "TBD"}{formtext: name=tbd_value; default=; cols=7}{endif}
{formtext: name=Id; cols=20; default=}

{note: preview=no}{formtoggle: name=toggle}{endnote}{if: toggle = no}{button: toggle = yes
; label=✍️}{else}{button: toggle = no
; label=↩️}{endif}{endrepeat}
{endnote}

{repeat: for x in countsub}Id : {=x.id}

The price is: {if: countsub[1].choice = "TBD"}{=countsub[1]["tbd_value"]}{else}{=x.choice}{endif}
{endrepeat}

Hi again,

I'm not quite sure I understood what you meant, but I think the solution you were looking for was [location(countsub, x)]. I edited the snippet abit.

{note}{yescount=count(filter(countsub, (x) -> contains(x, "yes")))}{repeat: 1 + yescount; locals=countsub}{note: preview=no}{formmenu: default=€5; €10; €20; TBD; name=choice}{endnote}{button: choice = "€5"
; label=€5}{button: choice = "€10"
; label=€10}{button: choice = "€20"
; label=€20}{button: choice = "TBD"
; label=TBD}{if: choice = "TBD"}
{formtext: name=tbd_value; default=; cols=7}{endif}
{formtext: name=Id; cols=20; default=}
{note: preview=no}{formtoggle: name=toggle}{endnote}{if: toggle = no}{button: toggle = yes
; label=✍️}{else}{button: toggle = no
; label=↩️}

{endif}{endrepeat}
{endnote}
{repeat: for x in countsub}Id: {=x.id}
The price is: {if: countsub[location(countsub, x)].choice = "TBD"}€{=countsub[location(countsub, x)]["tbd_value"]}{else}{=x.choice}{endif}

{endrepeat}The total price is €{=sum(map(countsub, x -> extractregex(x.choice & x.tbd_value, "\d+")))}