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

                                    I am hoping to get some guidance on how to add validation to control s based on a value in the database.

                                    For each control that I put on the page, there is information about the control that determines certain properties about it ( Allow multi-selection / Is it mandatory). This is looked up in the database.

                                    One of these properties determines if the field is Mandatory. This allows an Administrator of the application to determine if a field is mandatory and it can be changed at any time.

                                    I could not find any examples of how to add a "required" validator for this scenario. Are you able to point me in the right direction?

                                    Regards
                                    Brian

                                2 Solutions

                                Creation Date Importance Sort by

                                Thank you for your sample project.

                                From what I gather, you wish to use the jQuery unobtrusive validation. Our widgets doesn't support this validation type.

                                at least in some way colour the control to show that it is mandatory as I can do the checking myself

                                You already did it in the following code line:

                                [C#]
                                style = "background-color:" + (Model.IsMandatory ? "#ffece5" : "#ffffff")

                                Alternatively, you can manually render a div element with a required mark to the left of the widget's input field to inform a user that this field is mandatory.

                                If you wish to validate our widgets, I suggest you use the dxForm widget instead. Use the dxDropDownBox widget as a form item and set its validation rules conditionally. You can use the Validation demo as a starting point. If you have issues implementing the required functionality, please submit a new ticket and describe your current progress and the issue you faced.

                                • Customer3942 08.20.2019

                                  Hi Romeo,

                                  Yes, sorry I had already updated my Test to see if the style setting would work, but forgot to update my question to exclude it.

                                  On the validation part, you mention adding the dxDropDown Box as a form item, but in my demo you can see that I add all my dropdowns dynamically based off rules in the database. These are rendered using the Html.RenderPartialAsync() method. I could not find any documentation on how I could add these as ".items" to a dxForm. This is ok though and I can probably work around this, but the problem I see is that the validation in that demo you sent the link to uses [Attributes] on the Model properties to provide the validation. As you can see from my Demo, this will not work for me as it is not determined by a property in the model, but instead by a value in the database.

                                  You mention this in your response "Use the dxDropDownBox widget as a form item and set its validation rules conditionally".  Do you have any documentation that shows how to add these validation rules conditionally?

                                  Regards
                                  Brian

                                • Romeo (DevExpress Support) 08.21.2019

                                  You mention this in your response "Use the dxDropDownBox widget as a form item and set its validation rules conditionally".  Do you have any documentation that shows how to add these validation rules conditionally?

                                  We avoid discussing multiple subjects in one thread. It makes it difficult to follow the entire conversation. I've created a separate ticket regarding this inquiry. Please refer to it for further correspondence.

                                Hello Brian,

                                From what I gather, you need to set validation rules depending on information in your database. We don't have such an example.

                                I suggest you get the required information from your database in a controller and pass it to your view. In the view, you can configure DevExtreme widgets depending on the passed information.

                                If you have issues implementing this scenario, please create a simple runnable project illustrating your current progress and the problem. Send this project to us so that we can investigate it and assist you.

                                Regards,
                                Romeo

                                • Customer3942 08.19.2019

                                  Hi I have prepared a sample.

                                  The sample shows a page with two controls on it. The first control which is the devextreme dropdownbox I have tried adding the required attribute based on the "IsMandatory" property to the inputAttr. This is not working. The second control on the page which is just a standard Textbox control and I have added the required attribute to it... That control does standard validation on the form submit, but the dropdown box doesn't. 

                                • Ilya (DevExpress Support) 08.19.2019

                                  Hi,
                                  Please give us a bit more time to review your scenario.