Michael Lenaghan Posted April 9, 2024 Posted April 9, 2024 I created a `Fieldset (Page)` field with two fields, a start year and an end year. Is there some way to add validation that guarantees start year <= end year? (If, that is, they're specified at all; both fields should be optional.)
wbmnfktr Posted April 10, 2024 Posted April 10, 2024 The easiest way would probably be to use hooks in ready.php - something like the pseudo-code below: $pages->addHookBefore('Pages::saveReady', function(HookEvent $event) { $page = $event->arguments(0); // todo: change template name if($page->template == "your-template" { // todo: change field names $field1 = $page->dateStart; $field2 = $page->dateEnd; // todo: add validation if($field1 > $field2) { // show a message // whatever } } }); This would hook into the save process just before the page would be saved. Therefore you could check if the fields validate.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now