Describe the bug
A field is set as required in the field group. Using the acf/prepare_field/type=image filter, I'm changing the required parameter to false. However, when saving the page, the validation fails, and says the field is required. I suspect that acf/prepare_field is being called after the JavaScript has determined which fields to check for values. This order needs to be fixed.
My use-case is that during development we don't always have the images, so disabling the required parameter in those environments allows us to keep the requirement for staging and production environments.
To Reproduce
Steps to reproduce the behavior:
Create a field with the Required toggle on
Create a filter with acf/prepare_field and set required parameter to false
Notice that the asterisk is removed (indicating field is optional)
Attempt to save the post/page, and notice the error stating field is required
Expected behavior
Fields that aren't marked as required should not be required.
Screenshots or Video
Code
add_filter( 'acf/prepare_field/type=image', static function ( array $field ) : array {
if ( ! in_array( wp_get_environment_type(), array( 'local', 'development' ) ) ) {
return $field;
}
if ( empty( $field['required'] ) ) {
return $field;
}
$field['required'] = false;
$field['label'] .= ' <span style="color: #f00;" title="Required, but disabled in dev environment">*</span>';
return $field;
}
Describe the bug A field is set as required in the field group. Using the
acf/prepare_field/type=image
filter, I'm changing therequired
parameter tofalse
. However, when saving the page, the validation fails, and says the field is required. I suspect thatacf/prepare_field
is being called after the JavaScript has determined which fields to check for values. This order needs to be fixed.My use-case is that during development we don't always have the images, so disabling the required parameter in those environments allows us to keep the requirement for staging and production environments.
To Reproduce Steps to reproduce the behavior:
acf/prepare_field
and setrequired
parameter tofalse
Expected behavior Fields that aren't marked as required should not be required.
Screenshots or Video![2023-12-28T221405](https://github.com/AdvancedCustomFields/acf/assets/4573033/7ae81278-c694-406c-91fe-2509134e43b4)
Code
Version Information: