Validating the selected values from a joined table
Validating the selected values from a joined table
georgemcfly
Posts: 18Questions: 4Answers: 0
in Editor
I have an MJoin that joins a User table to a UserRoles table to a Roles table.
I want to perform some validation logic based on the selected Roles. For example, a new user can only be assigned the Admin role if the current user is an Admin.
I see examples of how to iterate through the DtRequest.Data to find individual field values in a server-side Validation method.
How do I iterate through the list of selected Roles values?
Answers
You would need a global validator for that:
https://editor.datatables.net/manual/net/validation#Global-validators
Here is a simple example from PHP which should work very similarly in .NET. Editor sends "many-count" fields to the server for Mjoins. Just check your browser's payload. I use that to validate whether the user selected anything if it is mandatory to select something.
But you can also loop through the data in a much more complex way.
This global validator really loops through the Mjoin values. You can see the nested foreach loop that performs that job. It takes all the "govdept" values from the Mjoin and checks against database values.
@rf1234 : Thanks for your quick response. I followed your lead and looped through the Roles dictionary looking for a specific role in the list.
I was hoping it would be as simple as foreach(var role in fields["Roles"]) but alas...