maxatwork/form2js — Issue #32: Add typing to form fields
Author: awvalenti
Created: 2012-01-21 15:16:11+00:00
State: open

Hello,

I'd like to contribute to form2js by implementing a way to specify field types on form inputs. This would avoid generating an object like { balance: "-1.50", active: "true" } where it should be { balance: -1.50, active: true }. The purpose of this issue is to discuss ideas to implement that.

I'm working on a web framework project which would benefit a lot from form2js. I wrote something similar to it, but it's only capable of converting simple form stuff.

Up to this point, the ideias I came up with are the following:

* Use the type attribute, like , instead of type="text". This is HTML5-like, and has the advantage of displaying a numerical keyboard on mobile devices, while degrading gracefully to type="text" on non-compatible browsers (as far as I know). However, it would break compatibility with type="hidden" and also seem strange on select elements, like (Eclipse displays a warning when validating XHTML).

* Add some string to the class attribute, like class="type-number" or "type-boolean". It's XHTML compatible and minimally intrusive.

This might eliminate the need for specifying value="on" or value="true" on boolean checkboxes, allowing the string "true" to be used where it actually means a string value.

Any ideas or comments?

Thank you!
André