remy / bind.js

bind.js - simple two way data binding to HTML and callbacks
694 stars 62 forks source link

Binding to an existing select wipes out options... #30

Closed bluecollardev closed 3 years ago

bluecollardev commented 8 years ago

I am using the following code to loop over my form fields and generate config for Bind...

`console.clear(); var prefix = '#form-product-p2p-filter '; var expr = /^product_(attribute|discount|special)[\d+]/, form = $('#form-product-p2p-filter').serializeArray().filter(function (obj) { return !obj.name.match(expr); });

var viewmodel = {},
    bindings = {};

$.each(form, function (idx, item) {
    var selector = prefix + '[name=' + item.name + ']',
        el = $(selector),
        type = el[0].tagName.toLowerCase(),
        value = null;

    if (type === 'select' || type === 'checkbox') {
        if (type === 'select') {
            //value = $(selector + ' option:selected').text();
            //console.log(value);
        } else {
            //value = el.val();
        }

    }

    viewmodel[item.name] = value; // Pull values from form on init
    bindings['basic.' + item.name] = selector;
});

var output = null;

bindings['basic'] = { callback: function () {
    console.log(output);
}};

var config = {
    questions: {
        has_shipping: null,
        has_vendor: null,
        has_dimensions: null,
        is_bookable: null
    },
    basic: viewmodel
};

console.log(config);
console.log(bindings);

output = Bind(config, bindings);`

For some reason, the binding works find on regular input elements, but all the options in all my select elements are getting wiped out. Any ideas?

BTW -- downgrading to v 1.0.1 fixed my issues.

LinhTran1 commented 8 years ago

I got the same problem and few other ones. After change to v1.1.0 all problems gone and Bind.js works like a charm.

englishextra commented 7 years ago

@LinhTran1 Fake accounts is not the way things are worked out.

mcdemarco commented 7 years ago

I'm having the same issue with 1.1.1 and 1.1.0; it can be reproduced by changing the source of bind.js in the JSBin form example to master.

shaack commented 3 years ago

This bug still seems to exist in 1.1.2., correct me, if I am wrong. Browser Chrome 86.0.4240.111, MacOS 10.15.7.

remy commented 3 years ago

Fixed and live in latest