acf-intl-tel-input
acf-intl-tel-input copied to clipboard
Validation improvements
Instead of simply removing the phone number when it doesn't match a given pattern, the number should stay there and maybe use the same method ACF uses to prevent saving the post when there's invalid fields.
This is pretty annoying because if before choosing a country you decide to write the phone no, it'll get erased even if it's valid.
Best thing to do would be trying to match the number against the different country-based placeholder the plugin shows after selecting one of them.
I have a copy of @lewebsimple's acf-phone
plugin in case you wanna take a look at how things were done there before he took it down from GitHub for some reason (GPLv2).
Let me know if you'd like me to try this in a PR or something else.
It surely need improvements. I did this in a very quick way... I think maybe I should add an option so you can choose how the phone gets validated. I'm not sure, but I think ACF uses server-side processing to prevent saving...as the International Telephone Input is a JS plugin, I think it's a no go... Maybe we can hook on before the form is submitted... Anyway let me check the files you have and think about it :)
Hi! Sorry for taking down the plugin, I was working on a new version which I've just put back online here: https://github.com/lewebsimple/acf-phone. This new version has support for extension number inside the same input field and should display a warning if JS is not available on the client side. Careful if you upgrade and you have phone extension data in your DB b/c they won't be migrated. Feel free to post issues in the new repo!
@jonyhayama ACF allows you to run JS on the admin to do whatever you need to.
- You can load custom JS: https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/
- And you can also prevent posts from saving: https://www.advancedcustomfields.com/resources/acf-validate_value/
Also now that @lewebsimple's plugin is back online, what would you guys think about merging both projects? I think they're both pretty similar and it would make it easier to maintain.