Created
February 22, 2011 03:50
-
-
Save insin/838187 to your computer and use it in GitHub Desktop.
js-forms & DOMBuilder on Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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