Phone input prefill country issue fixed (#213)

* fix prefill phone issue

* js phone parse fixes

* revert last change

* fix phone UI

* Code optimize

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
formsdev
2023-10-03 21:20:46 +05:30
committed by GitHub
parent 54f92f844f
commit f7ecd6f233
7 changed files with 310 additions and 38 deletions

View File

@@ -220,14 +220,14 @@ class AnswerFormRequest extends FormRequest
protected function prepareForValidation()
{
// Escape all '\' in select options
$receivedData = $this->toArray();
$mergeData = [];
collect($this->form->properties)->filter(function ($property) {
return in_array($property['type'], ['select', 'multi_select']);
})->each(function ($property) use ($receivedData, &$mergeData) {
$countryCodeMapper = json_decode(file_get_contents(resource_path('data/country_code_mapper.json')), true);
collect($this->form->properties)->each(function ($property) use ($countryCodeMapper, $receivedData, &$mergeData) {
$receivedValue = $receivedData[$property['id']] ?? null;
if (!is_null($receivedValue)) {
// Escape all '\' in select options
if(in_array($property['type'], ['select', 'multi_select']) && !is_null($receivedValue)){
if (is_array($receivedValue)) {
$mergeData[$property['id']] = collect($receivedValue)->map(function ($value) {
$value = Str::of($value);
@@ -244,6 +244,10 @@ class AnswerFormRequest extends FormRequest
)->toString();
}
}
if($property['type'] === 'phone_number' && (!isset($property['use_simple_text_input']) || !$property['use_simple_text_input']) && $receivedValue && in_array($receivedValue, $countryCodeMapper)){
$mergeData[$property['id']] = null;
}
});
$this->merge($mergeData);