Open 1yuv opened 11 months ago
The lib we use for formatting and validation has a function to getNumberType
which returns one of these types: https://javadoc.io/doc/com.googlecode.libphonenumber/libphonenumber/latest/com/google/i18n/phonenumbers/PhoneNumberUtil.PhoneNumberType.html
Should be reasonably easy to implement. I think I'd prefer validation options rather than a new type.
Possibly related: https://github.com/medic/cht-core/issues/6390
I also quickly verified by parsing some numbers on the library's node copy. This looks possible for most of the countries where it's possible to distinguish mobile number and fixed line numbers.
I think I'd prefer validation options rather than a new type.
If we want to do using validation, is it using constraint on forms? Isn't that mostly the part of enketo? Can we write our constraint functions? I was more inclined towards adding a new type mobile
, supporting only mobile phones and keeping tel
to support both fixed line and mobile.
We provide our own phone widget which validates against libphonenumber: https://github.com/medic/cht-core/blob/master/webapp/src/js/enketo/widgets/phone-widget.js
I don't know how to indicate different validation modes, but maybe we can use appearance
?
I'm removing my assignment given other priorities and leave it open for people to contribute to.
There's a solution being investigated for https://github.com/medic/cht-core/issues/8681 which includes the ability to pass parameters to widgets which I think would be helpful here too.
For the record, it should now be trivial to pass params to the Phone Widget following the pattern set for the instance::cht:unique_tel
in https://github.com/medic/cht-core/pull/9340.
For example, you could add a column to your form: like instance::cht:require_sms_support
. Then, in the phone-widget code, we would just need some simple logic to read the data-cht-require_sms_support
attribute and customize the libphonenumber call as necessary.
Could we extend the current phone_validation
setting?
Phone numbers can be entered using SMS forms also.
Sure, the phone-widget is already passing the settings values. The main impact of using an app_settings configuration is that it would apply to all phone numbers in all forms (unless you wanted to get really fancy...). But, maybe that would be desired behavior?
The other problem is you may want "full + mobile" or "partial + mobile", ie: they are two separate concepts, so we should define them separately.
I prefer passing params to the form because as @jkuester says this means you can have different validation for different fields.
I prefer passing params to the form
In that case, we will also need a way to specify the phone number type in an SMS/JSON form configuration.
we will also need a way to specify the phone number type in an SMS/JSON form configuration.
Would a new pupil validation rule, or the ability to pass a param to the existing validPhone
rule work?
Would a new pupil validation rule, or the ability to pass a param to the existing
validPhone
rule work?
I think it should work as long as it is configurable.
What feature do you want to improve? Allow an option to validate if given phone is Fixed line or Mobile number. Most of the time, when phone is registered on CHT, they're used for reporting or sending SMS. CHT currently allows user to input valid phone numbers
Describe the improvement you'd like If we're allowing to input fixed line numbers, to which messages can not be delivered, gateway phone tries and will fail. This impacts CHT performance, caused gateway to send messages to phones where message can not be sent or delivered at all.
Describe alternatives you've considered Allow a validation to be passed when
tel
input is used. Or, introduce a new typemobile
which accepts only mobile phone numbers.Additional context medic/config-moh-nepal#1067