Last active
October 30, 2016 23:37
-
-
Save travist/36ad3891db99646f1177d174f199f289 to your computer and use it in GitHub Desktop.
Force Field Validation Errors in Form.io
This file contains hidden or 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
| var forceFieldError = function(key, error) { | |
| var formioFormScope = angular.element('[name="formioForm"]').scope(); | |
| var formioScope = formioFormScope.$parent; | |
| var formioForm = formioFormScope.formioForm; | |
| var component = FormioUtils.getComponent(formioScope.form.components, key); | |
| component.customError = error; | |
| formioForm.$pristine = false; | |
| formioForm.$valid = false; | |
| formioForm[key].$setValidity('custom', false); | |
| formioForm[key].$pristine = false; | |
| formioScope.$apply(); | |
| }; | |
| var resetFieldError = function(key) { | |
| var formioFormScope = angular.element('[name="formioForm"]').scope(); | |
| var formioScope = formioFormScope.$parent; | |
| var formioForm = formioFormScope.formioForm; | |
| formioForm[key].$setValidity('custom', true); | |
| formioScope.$apply(); | |
| }; | |
| setTimeout(function() { | |
| forceFieldError('firstName', 'This name is bad!!!'); | |
| setTimeout(function() { | |
| resetFieldError('firstName'); | |
| }, 2000); | |
| }, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment