Skip to content

Instantly share code, notes, and snippets.

@insin
Created February 22, 2011 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insin/838187 to your computer and use it in GitHub Desktop.
Save insin/838187 to your computer and use it in GitHub Desktop.
js-forms & DOMBuilder on Node.js
> var forms = require("./js-forms");
> var TestForm = forms.formFactory({fields: function() {
... return {
... name: new forms.CharField(),
... age: new forms.IntegerField()
... };
... }});
>
> var f = new TestForm();
> f.toString()
'<tr><th><label for="id_name">Name:</label></th><td><input type="text" name="nam
e" id="id_name"></td></tr>\n<tr><th><label for="id_age">Age:</label></th><td><in
put type="text" name="age" id="id_age"></td></tr>'
>
> var f = new TestForm({initial: {name: "Alan", age: 46}});
> f.toString()
'<tr><th><label for="id_name">Name:</label></th><td><input type="text" name="nam
e" id="id_name" value="Alan"></td></tr>\n<tr><th><label for="id_age">Age:</label
></th><td><input type="text" name="age" id="id_age" value="46"></td></tr>'
>
> var f = new TestForm({data: {name: "", age: 46}, initial: {name: "Alan", age:
46}});
> f.toString()
'<tr><th><label for="id_name">Name:</label></th><td><ul class="errorlist"><li>Th
is field is required.</li></ul><input type="text" name="name" id="id_name"></td>
</tr>\n<tr><th><label for="id_age">Age:</label></th><td><input type="text" name=
"age" id="id_age" value="46"></td></tr>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment