A form builder, with default, but customisable markup, which displays validation and errors
The first argument is object, which can be anything, but should respond to the following methods
isNewRecord //has this object been persisted to the DB/Store?__factoryname //the name of the model, i.e 'Product', 'Book'
and any attributes it might have like id, title etc..
If you were for example using the Express framework, your new action may look like this..
// models.Product is a Sequelize.js model definitionvar product = modelsProduct;var form = product '/products';res;
And in your EJS view..
Which would render the following..
Notice how Formed has no opinion of markup, it only renders the form elements, you are responsible for the wrapping elements, lists, divs etc
Whilst Formed does not handle any validation by itself, it does include support for rendering errors to the client..
Consider a create action that fails using model validations..
// models.Product is a Sequelize.js model definitionvar product = modelsProduct;var errors = product;if !errors// Hurray, the form and data is fine, lets save and take them homeproduct;else// oh noes, let re render the form and ad pass in a hash of errors..var form = product '/products' id: 'new_product_form' errors;res;;
In your view..
Would output the following..
Invalid characters: titleString is empty: titleTitleInvalid characters: descriptionString is empty: descriptionDescriptionInvalid characters: imageString is empty: imageImage
Notice how form.error can print out multiple errors..
The error object passed in, would look something like this..
name: 'Invalid characters: name' 'String is empty: name'description: 'Invalid characters: description' 'String is empty: description'image: 'Invalid characters: image' 'String is empty: image'
Currently, it is primarily designed, to work with Sequelize.js, a great MySQL ORM for Node.JS.
It should however, be trivial to plug support into another adapter and i'm more that willing to accept patches to make the form builder more agnostic
Still needs a good way of defining selects, checkboxes and similar items..