Current filter:
                                You should refresh the page.
                                  • Hello,

                                    I'm wondering if there is a way to clear all validation errors from a dxValidation group?  I have a need to reset a form after clicking a submit button, but I don't want all the validation errors displayed immediately.  The reset() method does not fit my needs as this also resets the value of all validators in the group to their default value (null or 0), which isn't the value that their bound to ( AngularJS)

                                    For example :

                                    I have a dxDate Box defined in a dxValidationGroup

                                    [JavaScript]
                                    $scope.dueDateOptions = { placeholder: 'Select a due date', bindingOptions: { value: 'newInvoice.paymentDueDate' }, }; $scope.dueDateValidation = { validationRules: [{ type: 'required', message: 'Due date is required' }, { type: 'range', min: new Date(1753, 1, 1), message: 'Due date must be greater than 1/1/1753' }] };

                                    When I call reset the value of this editor is reset to null even though the binding value newInvoice.paymentDueDate is still set as a valid date.

                                    I've attached an example as well.

                                1 Solution

                                Creation Date Importance Sort by

                                Hi Mark,

                                Your scenario is not completely clear to me. From what I gather, you wish validation error messages to appear only after a submit button click. If so, consider implementing a custom adapter for your validator. Check to see if the code below suits your needs. You may also find more information about custom validation adapters in our documentation.

                                 

                                [JavaScript]
                                $scope.forceValidationBypass = true; $scope.dueDateValidation = { onInitialized: function(e) { var defaultAdapter = e.component.option("adapter"); e.component.option("adapter", $.extend( {}, defaultAdapter, { bypass: function() { return $scope.forceValidationBypass || this.editor.option("disabled"); } } )); }, validationRules: [{ type: 'required', message: 'Due date is required' }, { type: 'range', min: new Date(1753, 1, 1), message: 'Due date must be greater than 1/1/1753' }] }; $scope.save = function () { $scope.forceValidationBypass = false; var result = DevExpress.validationEngine.validateGroup($("#leftPane").dxValidationGroup("instance")); if (result.isValid) { // this will clear all validation errors and reset the values of the editors var validationGroup = $("#leftPane").dxValidationGroup("instance"); validationGroup.reset(); } $scope.forceValidationBypass = true; }

                                 
                                UPDATE:

                                If you need to remove validation errors on validationGroup.reset() and not to clear the actual values of editors you can use your custom 'reset()' method implementation of the dxValidator adapter. I've also provided you with an example of how this behavior can be reached. The 'clearErrors()' method of the scope will clear the validation errors.

                                [JavaScript]
                                $scope.dueDateValidation = { onInitialized: function(e) { var defaultAdapter = e.component.option("adapter"); e.component.option("adapter", $.extend({}, defaultAdapter, { reset: $.noop })); }, validationRules: [{ type: 'required', message: 'Due date is required' }, { type: 'range', min: new Date(2016, 0, 10), message: 'Due date must be greater than 1/1/1753' }] }; $scope.clearErrors = function(e) { var validationGroup = $("#leftPane").dxValidationGroup("instance"); validationGroup.reset(); };


                                If your scenario is different, please elaborate on it by providing screenshots or a project showing your desired result. We will be happy to suggest a more suitable solution to you.

                                • Mark Meyer - Civic 01.19.2016

                                  Hi Gregory,

                                  Sorry my example wasn't clear.  I'm looking for a way to just clear all validation errors and not clear the values.  I want the editors to validate as normal, I just don't want them to validate right after I clear out all my scope variables to reset my form.  I want it to look the same as it did when the user first entered the screen.  I've attached some screenshots.

                                  First Open Page - this is what it looks like when you first enter the page and what I want it to look like after clearing out the form
                                  After Clearing Screen - this is what it currently looks like after clearing form.  If I call the validationGroup.reset() it clears all those errors but also clears the values of editors I don't want cleared.

                                  Hopefully this helps!

                                  Thanks for looking this.

                                • Mark Meyer - Civic 01.19.2016

                                  Opps.  Missed the attachment

                                • George S. (DevExpress) 01.20.2016
                                  Mark,

                                  I've updated the solution according to your clarification. I hope that will help you resolve this problem.

                                • Mark Meyer - Civic 01.20.2016

                                  This works great.  Thanks George.

                                • George S. (DevExpress) 01.21.2016
                                  You are welcome, Mark!
                                  If you need any further assistance, feel free to contact us.