angularjs - Resetting a Formly form within an ng-repeat -


i have angular formly form inside ng-repeat. i've got working expect except reset button. reason clicking reset button resets last form, not 1 it's supposed to. submitting , updateinitialvalue() seem work fine.

<div ng-repeat="model in vm.models"> 

here form declaration inside repeat:

<formly-form model="model" fields="vm.fields" options="vm.options[$index]" form="vm.form[$index]"> 

and here reset button.

<button type="button" class="btn btn-default" ng-click="vm.options[$index].resetmodel()">reset</button> 

here whole thing in fiddle.

http://jsbin.com/feguvulumo/edit?html,js,output

thanks in advance can give!

i figured out @kentcdodds on formly gitter chat (https://gitter.im/formly-js/angular-formly)

he suggested issue repeating forms sharing same field configuration.

to fix it, implemented function called ng-init inside ng-repeat. builds array of fields objects loops.

function addfields() {   vm.fields.push(new getfields()); } 

i changed fields property on <formly-form> so

<formly-form model="model" fields="vm.fields[$index]" options="vm.options[$index]" form="vm.form[$index]"> 

full solution http://jsbin.com/yanopeyija/1/edit?html,js,output


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -