Twey
Twey

Reputation: 388

Dynamically-Sized List of Fields in Yesod

In HTML, multiple fields can be specified with a non-unique name like so:

<input type="checkbox" name="breakfast" value="eggs">
<input type="checkbox" name="breakfast" value="bacon">

so that, when submitted, query parameters get passed like (if both boxes are ticked) breakfast=eggs&breakfast=bacon. The CGI specification states that this should be interpreted as an array or list of values, and this technique is also useful for dynamically-sized lists of inputs:

<input type="text" name="url">
<input type="button" value="More…"
       onclick="var s = document.createElement('input');
                s.type='text';
                s.name='url';
                this.form.appendChild(s);
                return false;">

However, I can see no way to get list-valued inputs from a form in Yesod. Is there any way to do such a thing?

Upvotes: 4

Views: 752

Answers (1)

Michael Snoyman
Michael Snoyman

Reputation: 31315

Most of the prebuilt fields work on inputs with a single input (with a notable exception for multiSelectField). To achieve what you're looking for, you probably want to create a custom Field. Notice that the fieldParse function takes a list of Text values, specifically to allow your use case.

The chapter on forms includes a section on custom fields.

Upvotes: 3

Related Questions