theironcook / Backbone.ModelBinder

Simple, flexible and powerful Model-View binding for Backbone.
1.42k stars 159 forks source link

Fixed the issue #199 #207

Closed technikhil314 closed 9 years ago

technikhil314 commented 9 years ago

Changed the attr function to prop on line 303

technikhil314 commented 9 years ago

I have already discussed it with Kevin Partington which you can find it in the discussion of the issue.

platinumazure commented 9 years ago

I think a rough sketch for a unit test would look something like this:

test("Radio button 'checked' attribute should not override 'checked' property in view-to-model binding", function () {
    var View = Backbone.View.extend({
        render: function () {
            this.$el.empty();
            this.$el.append('<input type="radio" name="test" checked="checked" value="incorrect">');
            this.$el.append('<input type="radio" name="test" value="correct">');
            return this;
        }
    });

    var model = new Backbone.Model();

    var modelBinder = new Backbone.ModelBinder();

    var view = new View().render();
    view.$("[value=correct]").click();

    modelBinder.bind(model, view.$el, { myValue: "[name=test]" }, { initialCopyDirection: Backbone.ModelBinder.Constants.ViewToModel });

    strictEqual(model.get("myValue"), "correct");
});

Hope that helps.

technikhil314 commented 9 years ago

sure kevin will do it