quirkey / sammy

Sammy is a tiny javascript framework built on top of jQuery, It's RESTful Evented Javascript.
http://sammyjs.org
MIT License
2.99k stars 384 forks source link

Support for autogenerated ID for formbuilder #150

Open cardil opened 11 years ago

cardil commented 11 years ago

Hello I've added support for automated generation of form element IDs (they are required to work properly with label element). For example:

var item = {
    name: 'My Item',
    price: '$25.50',
    meta: {
        id: '123'
    }
};
var form = new Sammy.FormBuilder('item', item);
form.text('name');
//=> <input type="text" name="item[name]" value="My Item" class="item-name" id="item-name-31005" />
form.label('name', 'Enter name:');
//=> <label for="item-name-31005">Enter name:</label>

This integer from example: 31005 is generated from class-name field and it is there to be sure not to overlap with some other element ID on the webpage (ID should be unique)

You may also notice that I've changed apostrophe with quotation for HTML elements witch is more proper. It was:

<div class='test'>test</div>

and it is now:

<div class="test">test</div>

I've also modified unit tests to refer those changes

cardil commented 11 years ago

I've pulled latest changes from sammy v0.7.4 and added my fixes to form.js

cardil commented 8 years ago

Hello that have been a while. 3 years almost. Would you merge it? Is it still being developed?