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?
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:
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.
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.