Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

form.$invalid: true after ng-repeat array shortening #1312

Closed
Hoverbear opened this issue Aug 29, 2012 · 5 comments
Closed

form.$invalid: true after ng-repeat array shortening #1312

Hoverbear opened this issue Aug 29, 2012 · 5 comments

Comments

@Hoverbear
Copy link

Demonstration (Not by me):
http://jsfiddle.net/ADukg/117/

If you fill in both inputs, form.$invalid=false.
Then, if you click 'Remove All',form.$invalid=false, as expected.

However, if you fill none, or one input, form.$invalid=true, again, as expected.
But... If we click 'Remove All' after, form.$invalid=true remains, even though there are no fields in the form.

Is there a solution to this?

@ghost
Copy link

ghost commented Aug 29, 2012

I've also been struggling with this one for some time. Also happens for me when using array.splice to remove a row. I've tried a number of workarounds none of which have solved it so far. Any suggestions would be gratefully received.

@ghost
Copy link

ghost commented Aug 30, 2012

I've managed to solve my problem, not sure its the correct way, but I'm:

1: using an ng-form with the ng-repeat
2: insuring that I set the children controls to valid values before splicing

@laguiz
Copy link

laguiz commented Sep 27, 2012

@johnday-github
I also have issue with splice().
Can you give an example? I'm not sure to get it.
Thank you.

@laguiz
Copy link

laguiz commented Sep 27, 2012

I'm able to fix the issue when we want to splice() an array by doing this :

//The delete action
$scope.removeMyChild = function(currentParent, index){
    this.myParentForm.$removeControl(this.myChildForm);
    currentParent.myList.splice(index, 1);
}

This is not so nice but it works for me. Maybe AngularJS should handle it automatically?

Any feedback on this is welcome.

@pkozlowski-opensource
Copy link
Member

Duplicate of #1572

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants