set form element values

194 views
Skip to first unread message

me moi

unread,
Dec 5, 2013, 4:05:41 PM12/5/13
to backbon...@googlegroups.com

with this code :

    var modform = new Backbone.Form({

//Schema

schema: {

id:         'Number',

name:       'Text',

password:   'Password'

},

 

//Data to populate the form with

data: {

id: 123,

name: 'Rod Kimble',

password: 'cool beans'

}

}).render();

var html = modform.$el.html();

console.log(html);


I get  :


<fieldset data-fields=""> <div> <label for="id">Id</label> <div> <span data-editor=""><input id="id" name="id" type="number" step="any"></span> <div data-error=""></div> <div></div> </div> </div><div> <label for="name">Name</label> <div> <span data-editor=""><input id="name" name="name" type="text"></span> <div data-error=""></div> <div></div> </div> </div><div> <label for="password">Password</label> <div> <span data-editor=""><input id="password" name="password" type="password"></span> <div data-error=""></div> <div></div> </div> </div></fieldset>


None of the form elements gets values?

Any idea?

Thanks for your help

me moi

unread,
Dec 5, 2013, 4:16:59 PM12/5/13
to backbon...@googlegroups.com

me moi

unread,
Dec 6, 2013, 5:14:44 AM12/6/13
to backbon...@googlegroups.com
Ok I found out that appending the dom element does insert values : 

$('body').append(modform.el);

me moi

unread,
Dec 6, 2013, 5:32:10 AM12/6/13
to backbon...@googlegroups.com
backbone-form is very nice in fact, it works great.

It even works with html 5 new elements. By the way you could add :

/**
 * Color editor
 */
Backbone.Form.editors.Color = Backbone.Form.editors.Text.extend({
    initialize: function (options) {
        Backbone.Form.editors.Text.prototype.initialize.call(this, options);
        this.$el.attr('type', 'color');
    }
});

It works nicely on chrome :


 Thanks
Reply all
Reply to author
Forward
0 new messages