Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phone Input - option for simple text input #207

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Http/Requests/AnswerFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ private function getPropertyRules($property): array
}
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 [];
Expand Down
8 changes: 6 additions & 2 deletions app/Rules/ValidPhoneInputRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ public function passes($attribute, $value)
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()
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/forms/PhoneInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</small>
</div>
<div :id="id ? id : name" :name="name" :style="inputStyle" class="flex items-center">
<v-select class="w-[110px]" dropdown-class="w-[400px]" input-class="rounded-r-none" :data="countries"
<v-select class="w-[110px]" dropdown-class="w-[350px]" input-class="rounded-r-none" :data="countries"
v-model="selectedCountryCode"
:has-error="hasValidation && form.errors.has(name)"
:disabled="disabled" :searchable="true" :search-keys="['name']" :option-key="'code'" :color="color"
Expand Down
5 changes: 4 additions & 1 deletion resources/js/components/open/forms/OpenFormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default {
checkbox: 'CheckboxInput',
url: 'TextInput',
email: 'TextInput',
phone_number: 'PhoneInput'
phone_number: 'TextInput'
}
},
/**
Expand All @@ -159,6 +159,9 @@ export default {
if (field.type === 'signature') {
return 'SignatureInput'
}
if (field.type === 'phone_number' && !field.use_simple_text_input) {
return 'PhoneInput'
}
return this.fieldComponents[field.type]
},
isPublicFormPage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
checkbox: 'CheckboxInput',
url: 'TextInput',
email: 'TextInput',
phone_number: 'PhoneInput'
phone_number: 'TextInput'
}
}
},
Expand All @@ -57,6 +57,10 @@ export default {
required: true
}

if (this.property.type === 'phone_number' && !this.property.use_simple_text_input) {
componentData.component = 'PhoneInput'
}

if (['select', 'multi_select'].includes(this.property.type)) {
componentData.multiple = false;
componentData.options = this.property[this.property.type].options.map(option => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,18 @@
label="Field Name"
/>

<v-checkbox v-model="field.hide_field_name" class="mb-3"
<v-checkbox v-model="field.hide_field_name" class="mt-3"
:name="field.id+'_hide_field_name'"
>
Hide field name
</v-checkbox>

<v-checkbox v-model="field.use_simple_text_input" class="mt-3"
:name="field.id+'_use_simple_text_input'"
>
Use simple text input
</v-checkbox>

<!-- Pre-fill depends on type -->
<v-checkbox v-if="field.type=='checkbox'" v-model="field.prefill" class="mt-3"
:name="field.id+'_prefill'"
Expand All @@ -216,7 +222,7 @@
:date-range="field.date_range===true"
label="Pre-filled value"
/>
<phone-input v-else-if="field.type === 'phone_number'"
<phone-input v-else-if="field.type === 'phone_number' && !field.use_simple_text_input"
name="prefill" class="mt-3"
:form="field" :can-only-country="true"
label="Pre-filled value"
Expand Down
Loading