powmedia / backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
MIT License
2.17k stars 415 forks source link

Make list works with Backbone Collection #520

Closed brice closed 7 years ago

brice commented 7 years ago

Hello,

I'm currently working on a complex form where i have to display several item. When i tried to reload values on my form i discovered that i can't do it with Backbone Collection.

This piece of work (in extra/list.js) is not compatible with Backbone collection :

      //Add existing items
      if (value.length) {
        _.each(value, function(itemValue) {
          self.addItem(itemValue);
        });
      }

I think we should add something like that :

      //Add existing items
      if (value.length) {
          if (options instanceof Backbone.Collection) {
              value.each(function(itemValue) {
                    self.addItem(itemValue);
              });
          } else {
              _.each(value, function(itemValue) {
                    self.addItem(itemValue);
              });
          }
      }

What do you think?