-
Notifications
You must be signed in to change notification settings - Fork 58
validation of forms inside ng-repeat #26
Comments
This is a though one but so far, I manage to find the validationSummary inside the child scope. I get the angular element with the form name given in your $scope.validate=function(){
for(var key in $scope.items){
var formName=$scope.items[key].formName;
var form1 = angular.element(document.querySelector('[name="'+formName+'"]'));
var childScope = form1.scope();
console.debug(childScope[formName]);
if(new validationService().checkFormValidity(childScope[formName]))
alert("form "+formName+" is valid");
else
alert("form "+formName+" is invalid");
}
}; but the problem is that you need the Debug mode enabled, which is a mode you can disable for performance wise in Angular1.3+... See it here: Disabling Debug Data So I manage to find the |
I added your code and also made the validation rule to be applied dynamically http://plnkr.co/edit/WSjjdpVC9ck3NUw7iuKy?p=preview and have some observations i feel the validation fails for the last required field consistently because of which the form's validation is not calculated correclty... |
Well I'm sorry, it's hard for to help you debug that one, I rarely have so much dynamic forms. If you find a problem with regular code then I can help you for sure but something that is dynamic is harder to debug. I would suggest you to try using the non-minified code if you want to try debugging it. |
I'm working on something with dynamic forms and need to apply validation on those forms too. But, using your framework, validation keeps failing for the last required field and other than that validationservice's checkformvalidity() doesn't show error messages on fields. I can try to debug as you suggested using the non-minified code but as you have developed it ,you have a better understanding of the code rather than me. |
I made an update to my code last night which seems to have broke even your last code. What I can tell you is that the |
Alright, I made a copy of your plunker to my local code (it will be under the folder "more-examples") and debug everything, I found something that now seem to work but I need to do more much more tests just to make sure that I don't break anything else. It's getting late, so I'll go to bed, I will probably get something working tomorrow after all my tests are done. In the mean time, you should try to find another alternative to this piece of code: var form1 = angular.element(document.querySelector('[name="'+formName+'"]'));
var childScope = form1.scope(); Angular does not recommend finding the scope that way, as it is written in the documentation: Methods
|
I got the code wokring http://plnkr.co/edit/6HwgcYZpy4fgG0gQeQWQ?p=preview then i realized that interpolation is failing for the dynamic fields inside ng-repeat and since your validation framework depends on the element name to validate it, it was failing app.directive("dynamicName",function($compile){ added the name to the field and then compiled it during linking. With this the validation is able to find the element using name and validates it :) |
@ghiscoding, From a quick look, you seem to be using As a sidenote, Angular is able to handle fully dynamic names (e.g. a fields name changing at any time and as many times as we wish). It might be of little value and not worth the trouble trying to support this, but it would be very useful to at least support interpollated names (which are often used for |
Good, I will consider your approach... I was actually changing my code to use the Thanks for the info, you should expect a code commit later tonight. :) |
I push the code (v1.3.20) wish should fix your Dynamic Forms with ng-Repeat. I also re-created your plunker in the folder more-examples with the name of That should fix it. Enjoy it :) |
The plunker http://plnkr.co/edit/WSjjdpVC9ck3NUw7iuKy?p=preview is not working for some time. Its referring to your git repo for validation js. Previously you had mentioned that you had committed the required changes for this issue but it seems its still not fixed. |
I copied the code from your plunker to recreate a sample in the |
oh and by the way, your Plunker does not work because you are missing the $translate configuration. I got it working but I will not update it as I want you to use the code in the |
- Added possibility to use own isolated scope (issue #37 and #26). - Fixed an implementation issue found from last revision (issue #35). - Fixed email validation (issue #38). - Fixed a performance issue found with onBlur which would run as much validations as there was characters inside the input when onBlur was called (abcdef => would make 6 validations) and this was extremely costly with a Remote validation call. - Update the code of Remote validation to also accept the "As" alias "remote:vm.customRemoteValidation". - Finally added and updated a few Protractor tests to cover all of the above and more.
I added a new functionality see the Wiki - Isolated Scope and this also simplifies the original code I gave you, no more hacking to find the scope and all that weird way of coding. You can now call directly the // redefine which scope to use inside the Angular-Validation
$scope.$validationOptions = { isolatedScope: $scope };
$scope.validate=function() {
for(var key in $scope.items) {
var formName=$scope.items[key].formName;
if(new validationService().checkFormValidity($scope[formName])) {
$scope[formName].isValid = true;
}
else {
$scope[formName].isValid = false;
}
}
}; and the bonus is that you can now also disable the debug mode... |
@ghiscoding great work 👍 |
http://plnkr.co/edit/WSjjdpVC9ck3NUw7iuKy?p=preview
I have run into angular scope issues while trying to apply validation on forms inside ng-repeat.
Since i am creating the forms as well as the fields dynamically i am assigning the form name dynamically. Now i know that ng-repeat creates an isolated scope and i feel that, that is the reason why on calling validation on the form it is giving me error that the form object is not valid since the form exits inside the isolated scope of ng-repeat and not on the controller scope.
My problem is how do i share the scope in this situation. I have bumped into a couple of solutions but nothing seems to work. Was hoping maybe I could get some help here..
The text was updated successfully, but these errors were encountered: