What Version Of Caldera Forms, WordPress and PHP Are You Using?
WordPress Version: 4.9.8
PHP Version: 7.0.31
MySQL Version: 5.5.5
Caldera Forms Version: 1.7.2
Does Your Issue Persist When You Disable All Other Plugins and Switch To The Default Theme?
Yes
What Is The Unexpected Behaviour?
The Phone (better) field displays a Not a number error message when the field is empty, with both Use Country Code setting enabled or disabled.
If you click on the field or navigate with tab key and leave the field empty you get a Not a number validation message, the validation is performed on change, blur/focus, and submit events, so even if don't touch the field, the error displays briefly on form submission as well.
I would expect no validation error if the field is empty.
What PHP Errors Have You Logged While Reproducing This Bug?
No PHP errors.
What JavaScript Errors Have You Seen While Reproducing This Bug?
No JS errors.
I propose to change the validation function to handle both cases, empty field, and empty field with country code (Use Country Code enabled).
var validation = function () {
reset();
var valid;
var value = $.trim($field.val()); // field value
if (value) {
if ($field.intlTelInput("isValidNumber")) {
valid = true;
} else {
valid = false;
}
}
var message;
var errorCode = $field.intlTelInput("getValidationError");
var selectedCountryData = $field.intlTelInput("getSelectedCountryData"); // selected country data
if (0 == errorCode) {
valid = true;
message = '';
} else if ( value == "+" + selectedCountryData.dialCode ) { // Use Country Code enabled (this settings fills in the dial code as value)
valid = true;
message = '';
} else if ( ! value ) { // empty value
valid = true;
message = '';
} else {
if ('undefined' != field.messages[errorCode]) {
message = field.messages[errorCode]
} else {
message = field.messages.generic;
}
}
handleValidationMarkup(valid, $field, message, 'help-block-phone_better');
return valid;
};
Before
Use Country Code setting disabled, initial state
Use Country Code setting disabled, afterchange/blur/focus/submitevents
Use Country Code setting enabled, initial state
Use Country Code setting enabled, afterchange/blur/focus/submitevents
After
After proposed changes, no 'Not a number' validation error.
Do You Need Immediate Help?
No
Is This A Feature Request?
No
What Version Of Caldera Forms, WordPress and PHP Are You Using?
WordPress Version: 4.9.8 PHP Version: 7.0.31 MySQL Version: 5.5.5 Caldera Forms Version: 1.7.2
Does Your Issue Persist When You Disable All Other Plugins and Switch To The Default Theme?
Yes
What Is The Unexpected Behaviour?
The Phone (better) field displays a
Not a number
error message when the field is empty, with both Use Country Code setting enabled or disabled.If you click on the field or navigate with tab key and leave the field empty you get a
Not a number
validation message, the validation is performed onchange
,blur/focus
, andsubmit
events, so even if don't touch the field, the error displays briefly on form submission as well.I would expect no validation error if the field is empty.
What PHP Errors Have You Logged While Reproducing This Bug?
No PHP errors.
What JavaScript Errors Have You Seen While Reproducing This Bug?
No JS errors.
I propose to change the validation function to handle both cases, empty field, and empty field with country code (Use Country Code enabled).
Before
Use Country Code setting disabled, initial state
Use Country Code setting disabled, after
change/blur/focus/submit
eventsUse Country Code setting enabled, initial state
Use Country Code setting enabled, after
change/blur/focus/submit
eventsAfter
After proposed changes, no 'Not a number' validation error.