Dynamic form fields

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic form fields

nquirynen
Hi,

This subject has been spoken about more in the past, but I still have
not found a good solution to this and still struggle with this.

What is the best practice (Tapestry 5.4+) to add fields to a form
"dynamically". In my use case I just want to add some fields to a form
when a checkbox (also part of the same form) is selected, or remove/hide
them (in a way that they will not be validated and posted) when the
checkbox is deselected.

How do you guys handle these use cases with forms?

Nathan


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic form fields

bobharner
Nathan,

Have you tried the FormFragment component?

See
https://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/FormFragment.html


On Dec 14, 2017 5:47 AM, "Nathan Quirynen" <[hidden email]>
wrote:

Hi,

This subject has been spoken about more in the past, but I still have not
found a good solution to this and still struggle with this.

What is the best practice (Tapestry 5.4+) to add fields to a form
"dynamically". In my use case I just want to add some fields to a form when
a checkbox (also part of the same form) is selected, or remove/hide them
(in a way that they will not be validated and posted) when the checkbox is
deselected.

How do you guys handle these use cases with forms?

Nathan


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic form fields

Thiago H de Paula Figueiredo
In reply to this post by nquirynen
On Thu, Dec 14, 2017 at 8:47 AM, Nathan Quirynen <
[hidden email]> wrote:

> Hi,
>

Hi!


> This subject has been spoken about more in the past, but I still have not
> found a good solution to this and still struggle with this.
>
> What is the best practice (Tapestry 5.4+) to add fields to a form
> "dynamically". In my use case I just want to add some fields to a form when
> a checkbox (also part of the same form) is selected, or remove/hide them
> (in a way that they will not be validated and posted) when the checkbox is
> deselected.
>

Use BeanEditForm or BeanEditor, their 'model' parameters, which is of type
BeanModel, get one instance of it using BeanModelSource and add properties
to it using one of the beanModel.add() methods which receive a
PropertyConduit. In other words, you're creating synthetic properties, in
the sense that they don't map to an existing combination of
field/getter/setter in the class on which the BeanModel was created. Your
PropertyConduit implementation (actually, you'll probably have more than
one) is how you tell Tapestry how to get and set the value for that
property.

There's one example of doing this for editing a Map in
https://stackoverflow.com/questions/21675856/how-to-create-bean-edit-model-for-map-in-tapestry
.

--
Thiago
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic form fields

Norman Franke
In reply to this post by bobharner
That definitely works. You can also just add all the fields you’ll need to the form and then use JavaScript to hide fields that you don’t need at the time. This method is super simple, although you may need to validate some fields on the server side. Or set the values to null when you hide them.

-Norman Franke

> On Dec 14, 2017, at 8:16 AM, Bob Harner <[hidden email]> wrote:
>
> Nathan,
>
> Have you tried the FormFragment component?
>
> See
> https://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/FormFragment.html
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic form fields

nquirynen
In reply to this post by bobharner
Thanks,

This works perfect for my use case :)
Also when I want to trigger it by something else than a checkbox, for
example a change in a select, I can probably add a hidden checkbox that
I can check with javascript to toggle the FormFragment.

Greetings,

Nathan


Op 14/12/2017 om 14:16 schreef Bob Harner:

> Nathan,
>
> Have you tried the FormFragment component?
>
> See
> https://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/FormFragment.html
>
>
> On Dec 14, 2017 5:47 AM, "Nathan Quirynen" <[hidden email]>
> wrote:
>
> Hi,
>
> This subject has been spoken about more in the past, but I still have not
> found a good solution to this and still struggle with this.
>
> What is the best practice (Tapestry 5.4+) to add fields to a form
> "dynamically". In my use case I just want to add some fields to a form when
> a checkbox (also part of the same form) is selected, or remove/hide them
> (in a way that they will not be validated and posted) when the checkbox is
> deselected.
>
> How do you guys handle these use cases with forms?
>
> Nathan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]