Search code examples
javascriptbackbone.jsmarionette

Backbone Stickit erases dinamically rendered inputs


I render some inputs dinamically with javascript. Example:

render: function (id, val) {
            return '<input id="' + id + '" value="' + val + '"/>'
        }

After that I call this.stickit(); in my view render function but it erases values of rendered inputs (I guess it's because of model is empty).

How to solve this?


Solution

  • I found a workaround but I'm not sure it's a good way. The idea is to disable updates of view coming from a model:

    bindings: {
                '#id_of_input': {
                    observe: 'name_of_attribute',
                    updateView: false,
                    setOptions: {
                        validate: true
                    },
                    events: ['change', 'blur', 'focus']
                }
     }
    

    But after we rendered an input and filled it with a data we must trigger 'change' event on the input to update bounded model attribute.

    This is a good solution for now because I don't use my model to update a view. But in case we want two-way binding (model <-> view) I still don't know the solution.