From 4c56e8ba8545b7e105eb7e924b4bfcf5d3aed3ee Mon Sep 17 00:00:00 2001 From: formsdev <136701234+formsdev@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:44:08 +0530 Subject: [PATCH] Phone Input - option for simple text input (#207) Co-authored-by: Julien Nahum --- app/Http/Requests/AnswerFormRequest.php | 3 +++ app/Rules/ValidPhoneInputRule.php | 8 ++++++-- resources/js/components/forms/PhoneInput.vue | 2 +- resources/js/components/open/forms/OpenFormField.vue | 5 ++++- .../form-logic-components/ColumnCondition.vue | 6 +++++- .../open/forms/fields/components/FieldOptions.vue | 10 ++++++++-- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/Http/Requests/AnswerFormRequest.php b/app/Http/Requests/AnswerFormRequest.php index d7c0244..41073bb 100644 --- a/app/Http/Requests/AnswerFormRequest.php +++ b/app/Http/Requests/AnswerFormRequest.php @@ -190,6 +190,9 @@ class AnswerFormRequest extends FormRequest } return $this->getRulesForDate($property); case 'phone_number': + if (isset($property['use_simple_text_input']) && $property['use_simple_text_input']) { + return ['string']; + } return ['string', 'min:6', new ValidPhoneInputRule]; default: return []; diff --git a/app/Rules/ValidPhoneInputRule.php b/app/Rules/ValidPhoneInputRule.php index 9e6c728..440ed5c 100644 --- a/app/Rules/ValidPhoneInputRule.php +++ b/app/Rules/ValidPhoneInputRule.php @@ -13,8 +13,12 @@ class ValidPhoneInputRule implements Rule return false; } - $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); - return $phoneUtil->isValidNumber($phoneUtil->parse($value)); + try { + $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); + return $phoneUtil->isValidNumber($phoneUtil->parse($value)); + } catch (\Exception $e) { + return false; + } } public function message() diff --git a/resources/js/components/forms/PhoneInput.vue b/resources/js/components/forms/PhoneInput.vue index 9809af0..68a16ce 100644 --- a/resources/js/components/forms/PhoneInput.vue +++ b/resources/js/components/forms/PhoneInput.vue @@ -13,7 +13,7 @@
- { diff --git a/resources/js/components/open/forms/fields/components/FieldOptions.vue b/resources/js/components/open/forms/fields/components/FieldOptions.vue index 994ea6d..e243cab 100644 --- a/resources/js/components/open/forms/fields/components/FieldOptions.vue +++ b/resources/js/components/open/forms/fields/components/FieldOptions.vue @@ -193,12 +193,18 @@ label="Field Name" /> - Hide field name + + Use simple text input + + -