Fix: Allow empty values in optional email fields#7483
Closed
faisalahammad wants to merge 1 commit intopods-framework:release/3.3.5from
Closed
Fix: Allow empty values in optional email fields#7483faisalahammad wants to merge 1 commit intopods-framework:release/3.3.5from
faisalahammad wants to merge 1 commit intopods-framework:release/3.3.5from
Conversation
Fixes issue pods-framework#7476 where optional email fields (not marked as required) were incorrectly showing validation errors when left empty. The JavaScript email validator was treating empty strings as invalid values, causing the "Invalid email address format" error even for optional fields. This commit updates the validation logic to only validate non-empty values, allowing optional fields to be saved with empty email addresses. Changes: - Modified emailValidator function to check if value exists before validating format - Rebuilt minified JavaScript assets Testing: - Created optional email field (not required) - Added valid email address and saved successfully - Removed email address (made empty) and saved without errors - Verified required email fields still work correctly - Tested with invalid email format still shows proper error
PR Summary
|
Member
|
Merged manually via 4a70872 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
This pull request fixes issue #7476 where optional email fields (fields not marked as required) were incorrectly showing validation errors when left empty. When a user tried to save a post with an empty optional email field, they would see "Invalid email address format" error and then "Please complete these fields before saving: Email" message, preventing them from saving the content.
Problem Description
The JavaScript email validator was using a condition that treated empty strings as invalid values. The validation logic
if ( ! value || ! value.match( EMAIL_REGEX ) )meant that if a value was falsy (empty string, null, undefined) OR didn't match the email regex, it would throw an error. This meant optional fields could never be saved empty.Solution
Updated the
emailValidatorfunction inui/js/dfv/src/helpers/validators.jsto only validate non-empty values:Before:
After:
This change ensures that:
Changes Made
ui/js/dfv/src/helpers/validators.js- Updated emailValidator functionui/js/dfv/pods-dfv.min.js- Rebuilt minified JavaScriptui/js/dfv/pods-dfv.min.asset.json- Updated asset dependenciesTesting Steps
I have thoroughly tested this fix with the following scenarios:
Test Case 1: Optional Email Field - Empty Value
Result: Post saves successfully without any errors
Test Case 2: Optional Email Field - Valid Email
test@example.comResult: Post saves successfully
Test Case 3: Optional Email Field - Remove Email
Result: Post saves successfully without errors (this was previously broken)
Test Case 4: Optional Email Field - Invalid Email Format
not-an-emailResult: Shows "Invalid email address format" error (expected behavior)
Test Case 5: Required Email Field - Empty Value
Result: Shows "Email is required" error (expected behavior works correctly)
Test Case 6: Required Email Field - Valid Email
Result: Saves successfully (works as expected)
Environment Tested
Additional Notes
The PHP-side validation in
classes/fields/email.phpwas already handling empty values correctly. The issue was purely in the JavaScript client-side validation. This fix aligns the JavaScript validation behavior with the PHP validation logic.Required field validation is handled separately through other validation mechanisms, so this change only affects the email format validation portion.
Checklist
Related Issue
Fixes #7476
Screen recording
https://videos.faisalahammad.com/recordings/8O6tgvIXigVMg4EdXbta