I created a validation in the "Client Action" to check if Admission date is bigger than Demission date, but I would like to know, if this type of validation should be in a "Client Action" or "Server Action" ?
In attachment is OML.
Hi Vivian,
Checks that show information to the user about the data they entered, like errors or warnings, can be done client-side. However, keep in mind that a tech-savvy user could, theoretically, change the client-side code to bypass these checks. That's why the server-side save action should also check for data validity (as these checks can't be hacked).
So, a general rule would be that in the On Change of an input you can call a Client Action to validate the data to provide feedback to the user, but in the Server Action that actually stores the data in the database you should also perform validation, to ensure no bad data can be saved, even if the user has bypassed the client-side validations.
Note that client-side validation is optional: it's nice to warn the user immediately if they entered a wrong value, but you could choose to have the Server Action return a list of errors and show that to the user.
Thanks so much @Kilian Hekhuis for explained.
So would it be right to do it this other way? How this picture.
But, now is appearing a message in "EmployeeCreateOrUpdate".
"The 'SaveDetail' Client Action calls several Server Actions. To avoid performance issues, group them all in a single Server Action and call it instead."
You should have validations in both client and server side for the reason mentioned by @Kilian Hekhuis .
The warning you see on the screen is for a different reason. In your save action you are calling two server actions a) ValidationNEW b) EmployeeCreateOrUpdate. This cause 2 round trip to the server and hence it is a performance issue.
I can see that you are reusing the Validation Server action (ValidationNEW) on the client side. Please create a separate validation for Client Side like you had before (ValidateEmployee Client Action) and use it in the Save. Also invoke the ValidateNEW Server action inside the EmployeeCreateOrUpdate Server Action
Thanks so much @Siya I changed and put validate in the 2 side (1 client + 1 server).
Is there any way to write this IF, in only a place, and call him here (client + server) ?
Because, everytime that business change, I will have to change in these 2 places.
In order to make it common you might have to put all the validation logic inside a server action (since client action cannot be invoked from server action) which would then imply that all the validations ends up in server side logic. You could go this route but then you lose the swiftness and user friendliness of client side validations
Talking of changes in business logic and maintaining it at two places - Usually core business logic is kept on server side, which is different from the validation logic. I would suggest you to separate the validation logic from business logic to avoid the overhead of maintenance at multiple places. This is also the approach used to build flexible business components open to interact through different interfaces (web page, APIs etc.).
Thanks so much @Junaid SyedBut, I don't know if I understood correctly, but from what people explained was that the same validations should exists in the side of server too, because if a hacker to cheat the interface/browser, the part of server whouldn't let it pass.
Hi,
Most of the form validations are client side which not compare with DB data are client actions.
Hi Vivian
This message appears because for Best Practices it is not recommended to have 2 or more server actions inside a client action.
My recommendation would be:
In the client Action, perform the form validation, and if it is correct, call a server action to validate and make the create or update. That mean, inside that Server Action (ValidateAndEmployeeCreateOrUpdate) you would have the content of ValidateNEW server action and the call to EmployeeCreateOrUpdate.