Reputation: 255
How can I show all validation errors on submit with formly?
form
<formly-form model="vm.model" fields="vm.fields" form="vm.form">
<button class="btn btn-primary" type="button" ng-click="submit()">Save changes</button>
</formly-form>
controller
$scope.submit = function () {
if (!$scope.form.$valid) {
$scope.form.$setUntouched();
}
};
I find just form.$setUntouched() method in angular.js to hide errors.
Upvotes: 1
Views: 709
Reputation: 255
Config:
app.run(function(formlyConfig) {
formlyConfig.extras.errorExistsAndShouldBeVisibleExpression = 'fc.$touched || form.$submitted';
});
Controller:
$scope.submit = function () {
$scope.form.$submitted = true;
if ($scope.form.$valid) {
// Do submit
}
};
Upvotes: 1