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}

2 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