How can I validate that time inputs are logical?

Hello Wix/Corvid community,

I have a form on my site where users can enter their availability, which is a window of time for each day of the week. This is done with two “time pickers” on each day, a start time and an end time. The time pickers default to a logical time frame (e.g. 9am - 5pm) but users have the ability to adjust the times to be illogical (e.g. 1pm-10am). I’d like to validate that times are logical before they submit the form, but I am having trouble figuring it out.

For some context, I’m currently not using any code at all for the form. Each element is connected to an item in a dataset using the UI on the non-dev side of things. I’m open to trying to do the form entirely with code, if need be, but I’d prefer to have as little code to worry about as possible.

Thanks in advance!

Hello.

You can use the getDuration () here and use validation to check if the returned value is negative and return an error message.

If you are using code to perform custom validation, it would be advisable to use code to insert data to a database collection too since using both data binding and code sometimes may result in inconsistency in element functionality.

Good luck!