Last active
August 29, 2015 14:27
-
-
Save deyceg/ff72acb0009d5c1a385b to your computer and use it in GitHub Desktop.
Schema Form Partial Validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateOnCollapse(){ | |
var accordionScope = accordionCtrl.groups[scope.$index]; | |
accordionScope.$watch('isOpen', function(newVal, oldVal) { | |
if(newVal === false){ //closing | |
$rootScope.$broadcast('schemaFormValidate', obj); | |
} | |
if(accordionForm.$invalid){ | |
accordionScope.isOpen = true; | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope.$on('schemaFormValidate', function(evt, f) { | |
var match = false; | |
var form = getForm(); | |
schemaForm.traverseForm(f, function(part){ | |
if(match) return; | |
match = angular.equals(form.schema, part.schema) | |
}) | |
if(match){ | |
if (ngModel.$setDirty) { | |
// Angular 1.3+ | |
ngModel.$setDirty(); | |
validate(ngModel.$modelValue); | |
} else { | |
// Angular 1.2 | |
ngModel.$setViewValue(ngModel.$viewValue); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment