Ticket T802352
Visible to All Users

Form - Server-side validation

created 6 years ago

Hello,
I want to validate my form on server side. I'm using dx-form, and this form contains many dx-items.
Normal flow of application would be like this:
- User clicks submit buttons.
- Client side validations fires.
- An ajax call to server side upon client validation successfully.
- Server throws error with information, what field error has occurred and error message.
- Client receives this error.
Now I want to display this as an error message on given field.
How can I do this?
I've read documentation here: Server-Side ValidationBut it does not illustrate this scenario.

Comments (2)
Alessandro (DevExpress Support) 6 years ago

    Hi,

    The help section you mentioned contains a sample that sends the server request and accepts the result from the server along with the error message: 2019-07-30_1213.png. Please let me know if I missed anything important.

    RA RA
    Rudrik Andharia 6 years ago

      Hello Alessandro
      I think you did not understand my question.
      Where is submit button in the example given in documentation?
      Where is a dx-form instance in the example?
      In question, I've clearly mentioned that user clicks a submit button.
      Also I've mentioned that I'm using dx-form.
      Please read the question carefully.

      Answers approved by DevExpress Support

      created 6 years ago

      Hi,

      Thank you for your clarification. The same approach is applicable to the dxForm widget. It uses our data editors in its container. So, the Data Validation concept is applicable there as well.

      Use the Validation demo as a starting point and add "custom" validation rules with validationCallback by using the syntax illustrated in the aforementioned help section: Server-Side Validation. Should you need further clarification, feel free to ask. I will be happy to help you.

      See Also:
      Validate and Submit the Form

      Thanks,
      Alessandro

        Show previous comments (1)
        Alessandro (DevExpress Support) 6 years ago

          Hi,

          Thank you for your clarification. In this scenario, you can use the following logic:

          JavaScript
          var fnEditor = $("#formContainer").dxForm("instance").getEditor("FirstName"); $.getJSON(SERVICE_URL).done(function (result) { fnEditor.option({ validationError: { message: result[0].title }, isValid: false }); });

          https://codepen.io/anon/pen/EqXaYg

          The key idea is to access the required editor instance via the getEditor method and specify the validationError and isValid options explicitly based on the server result. I hope this helps you.

          RA RA
          Rudrik Andharia 6 years ago

            Thanks Alessandro for this solution.It worked well for me.
            I don't know why this is not documented with help section: Server-Side Validation.

            Alessandro (DevExpress Support) 6 years ago

              Hi,

              The approach you chosen does not use the built-in validationCallback. This is the standard way to implement server-side validation. So, it is documented in the aforementioned article. As for your approach, it uses the custom logic with a separate button and manual callback to the server.

              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.