Ticket T618853
Visible to All Users

Form - Custom Validation doesn't work

created 7 years ago

Hi, I have a problem. I have created a custom validation attribute, created the adapter, provider, registered it and wrote the javascript code. I can see everything load, but the java script code is not called. I think it is because the adapter writes attributes to the HTML generated and when using a devextreme form, the HTML is not generated in the traditional way. According to this article Client Side Validation - DevExpress you guys support the "custom" attribute. How do I get my custom attribute to execute client side validation with a devextreme form? Thanks.

Comments (3)
Artem (DevExpress Support) 7 years ago

    Hi,

    A custom validation rule should be automatically checked after an editor value is changed. There shouldn't be any difference between solutions for a stand-alone editor and the Form widget. We would need to review your code to see what goes wrong. Could you please post your Form and Data Annotation attribute code files for further examination? We'll do our best to put you on the right track.

      Can you give me an example of a Core 2 Razor pages app, using a DevExtreme form, with a custom attribute used for validation? Perhaps I am just missing a step?

      Vova (DevExpress Support) 7 years ago

        Hello,

        I reproduced the described issue while creating an example. I need to discuss this issue with our developers. We will update this ticket as soon as we have any news.

        Regards,
        Vova

        Answers approved by DevExpress Support

        created 7 years ago (modified 7 years ago)

        Hello,

        I discussed this question with our developers. It's necessary to define the ValidationGroup widget as in the Validation demo. I created a sample project based on the Implement a Custom Validation Rule article demonstrating how to use the custom validation rule. Please review the attachment and let me know if this sample helps.

        Regards,
        Vova

          Comments (2)

            I was missing the "-custom-*" when adding the attributes to the HTML. This now works. I do have another question though. How can I force validation? The problem I have is this: I am using custom attributes to do validation. I have 4 dates in the form. The first date must be before any of the other dates. The problem is that it is the first date listed on the form, so when it goes to validate the first time, the other dates aren't filled in and it validates incorrectly. How can I call it's validate after all of the other dates have filled in, so that it properly shows me the correct validation message? I tried manually calling it's validate method, but I can't seem to find a valid method. Here is one approach I took:

            JavaScript
            $("#formPool").dxForm("instance").getEditor("IssueDate").validate(); //No Method called validate $("#formPool").dxForm("instance").getEditor("IssueDate").component.validate(); //No Method called validate
            DevExpress Support Team 7 years ago

              Hello,

              I've created a separate ticket on your behalf (T619968: How to manually call validation). It has been placed in our processing queue and will be answered shortly.

              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.