Dynamically-Sized List of Fields in Yesod

Deadly 提交于 2019-12-23 20:28:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/11485186/dynamically-sized-list-of-fields-in-yesod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!