From 550468aefb8418cb3e0ae1b7344e6da4f885de7f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 15 Feb 2018 14:51:31 -0700 Subject: [PATCH] Added checkbox-style support for `switch` field --- CHANGELOG.md | 1 + system/src/Grav/Common/Data/Validation.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c627530c0..44ce78860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ 1. [](#improved) * Better `Page.collection()` filtering support including ability to have non-published pages in collections * Stopped Chrome from auto-completing admin user profile form [#1847](https://github.com/getgrav/grav/issues/1847) + * Support for empty `switch` field like a `checkbox` 1. [](#bugfix) * Properly validate YAML blueprint fields so admin can save as proper YAML now [addresses many issues] * Fixed OpenGraph metatags so only Twitter uses `name=`, and all others use `property=` [#1849](https://github.com/getgrav/grav/issues/1849) diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index efa9cd98d..8ab5cf185 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -33,7 +33,7 @@ class Validation $method = 'type'.strtr($type, '-', '_'); // If value isn't required, we will stop validation if empty value is given. - if ((empty($validate['required']) || (isset($validate['required']) && $validate['required'] !== true)) && ($value === null || $value === '' || ($field['type'] === 'checkbox' && $value == false))) { + if ((empty($validate['required']) || (isset($validate['required']) && $validate['required'] !== true)) && ($value === null || $value === '' || (($field['type'] === 'checkbox' || $field['type'] === 'switch') && $value == false))) { return $messages; }