danhunsaker / angular-dynamic-forms

Build Forms in AngularJS From Nothing But JSON (please see Alternatives in the README)
MIT License
379 stars 140 forks source link

Change the standard multiple element #53

Open mystertb opened 9 years ago

mystertb commented 9 years ago

Hi,

thank you for this amazing framework ! I'm trying to change the default multiple behavior. I want to have a select element and a button below. When i click on the button ("Ajouter"), the current selected element is appended to a div element below the button. I implemented the mechanism with the framework, it works well:

image But there is no connection with the model. The data binding is not occuring. I changed those lines:

Line 119:

if (!(angular.isDefined(field.multiple) && field.multiple !== false)) {
                  newElement.attr('ng-model', bracket(field.model, attrs.ngModel));
                  // Build parent in case of a nested model
                  setProperty(model, field.model, {}, null, true);
                  }

Line 214:

if (angular.isDefined(field.multiple) && field.multiple !== false) {
                      field["classname"] += " multiple "; 
                  }

Line 308:


 newElement = newElement.wrap('<label class="col-xs-12"></label>').parent();
  newElement.prepend(document.createTextNode(field.label + ' '));

 if (angular.isDefined(field.multiple) && field.multiple !== false) {

                        newElement.append("<div class='col-xs-12 btn btn-default' data-textmultiple='"+field.id+"'>Ajouter</div>");
                        var div = angular.element("<div class='"+field.id+"_multiple' value='myinput'/>");
                                //The binding doesn't work :/
                        div.attr("ng-model",bracket(field.model, attrs.ngModel));
                        newElement.append(div);
                    }

Is there something else to change to have data-binding with the div ?