Ticket T351537
Visible to All Users

Reset Validator errors

created 9 years ago

Hi -

I use dxValidators with the validationEngine.   All works as expected.

When I navigate back to this page from my app, I need to clear the fields.  I use the viewShown event to clear the fields.  Clearing the fields causes the dxValidators to indicate errors.  There should be no errors visible until the user interacts with the screen.

I have looked for the reset() function, but I can't seem to find it in any of the objects available.

Find attached sample app demonstrating the problem.  Hit the 'Scan' button to navigate to a second page.  Hit the back arrow to return to the initial page. The problem will be visible.

Thank you.

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hello Austin,
The reset() method is available on dxValidationGroup. So, you can wrap your widgets into the validation group and call its reset method. I've attached an updated sample. Let me know whether or not it suits your requirements.

    Show previous comments (5)
    DevExpress Support Team 9 years ago

      Hi Austin,

      In the case of Knockout, your view model is already a default group. dxValidationSummary uses it. You can specify a custom dxValidationGroup, but you will need to specify dxValidator for an editor, not for a view model property:

      HTML
      <div id="group" data-bind="dxValidationGroup: {onInitialized: onInitialized}"> <div id="scan" class="dx-field-value_cgs" data-bind="dxTextBox: { value: Scan, valueChangeEvent: 'input', onEnterKey: doScan }, dxValidator: { validationRules: [{ type: 'required', message: 'Scan is required.' }] }"></div> <div id="user" class="dx-field-value_cgs" data-bind="dxTextBox: { value: User, onEnterKey: doScan }, dxValidator: { validationRules: [{ type: 'required', message: 'User is required.' }] }"></div> <div data-bind="dxValidationSummary: { }"></div> <div class="dx-scan-button_cgs" data-bind="dxButton: { text: 'Scan', onClick: doScan }"></div> </div>

      Then, you can validate this group and reset it like:

      JavaScript
      var viewModel = {   Scan: ko.observable(""), User: ko.observable(""),    viewShown: function () { //We need to clear the two fields each time the page is shown   this.Scan(""); this.User(""); DevExpress.validationEngine.resetGroup(viewModel.group);   },   doScan: function (doScanParams) {   var validator = DevExpress.validationEngine.validateGroup(viewModel.group); ValidatorProblem.app.navigate('Page2'); }, group: null, onInitialized: function (e) { viewModel.group = e.component; } };

      In my opinion, setting a custom validation group in the Knockout approach makes sense when you need to validate some editors separately from others. So, I would use view model validation in your case.

        Thank you for the clarification.

        DevExpress Support Team 9 years ago

          You are welcome, Austin!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.