diff --git a/changelog.txt b/changelog.txt index 94ccbb07179ae4f2ca1914816b86b90e6d0b71ba..0886a14e19d7b41c274d3500a193e569ec42f7f3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,9 @@ # Changelog +## [2.4.2] - 2021-03-10 +### Fixed +- When no value is provided use default in validation + ## [2.4.1] - 2021-02-01 ### Fixed - Invalid namespaces diff --git a/src/Form/FormWithFields.php b/src/Form/FormWithFields.php index 84dbf8073a6005efc3c011eae4fb799b0dc0c1a8..4b5819cd6393de3b5c70d6305e2ab17627818c00 100644 --- a/src/Form/FormWithFields.php +++ b/src/Form/FormWithFields.php @@ -117,7 +117,7 @@ class FormWithFields implements Form, ContainerForm, FieldProvider { */ public function is_valid() { foreach ( $this->fields as $field ) { - $field_value = isset( $this->updated_data[ $field->get_name() ] ) ? $this->updated_data[ $field->get_name() ] : null; + $field_value = isset( $this->updated_data[ $field->get_name() ] ) ? $this->updated_data[ $field->get_name() ] : $field->get_default_value(); $field_validator = $field->get_validator(); if ( ! $field_validator->is_valid( $field_value ) ) { return false;