Make it easier to individually output the fields. #7

miracle2k opened this Issue Apr 11, 2011 · 2 comments

2 participants


This is currently somewhat tedious. Not only there no way to call simply call "form.FOOFIELD.toHTML()" and have it print the html in a template, when writing the field html tags manually, you would want to persist the user's input in case of an error, so you would need to do something like this:

<input type="question" value="<%= %>">

This will cause problems in some template languages however (like EJS) when the form is unbound, and therefore does not exist. I suggest that the data dictionary should exist anyway, and contain empty strings, or null/undefined values.

On a somewhat related note, the "empty" callback currently is only called if no request object is passed; the example in the readme makes it sound like it is supposed to be called if the given request object contains no data. I understand the latter might be hard to determine due to GET and POST (a user might have a page with a querystring and a form that POSTs), but depending on how the design is supposed to work, I suggest that the example in the readme be updated to something like:

 if (QuestionForm.handle(req.method == 'POST' ? req : undefined, {
    empty: function() {  ... }

As the empty example currently stands, a user is likely to find that empty is not called the way he expects to.


For your first example, where you want user's input to persist, you can form.bind(request) and the data should be there for you. I use it this way, with EJS, with no problems or need to output individual fields.

Please submit a pull request with the changes you'd like made to the README. Thanks!


Opened 2 years ago, request for comment 1 year ago - closing.

@ljharb ljharb closed this Apr 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment