Skip to content

Commit

Permalink
Merge pull request #1245 from prabhat-webkul/fix-1239
Browse files Browse the repository at this point in the history
fixed 1239
  • Loading branch information
devansh-webkul authored Jun 18, 2024
2 parents e449e8a + ab34f81 commit bde276d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/Webkul/WebForm/src/Http/Requests/WebForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Webkul\Core\Contracts\Validations\Decimal;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Attribute\Repositories\AttributeValueRepository;
use Webkul\WebForm\Rules\PhoneNumber;

class WebForm extends FormRequest
{
Expand Down Expand Up @@ -102,7 +103,7 @@ public function rules()
} else if ($attribute->type == 'phone') {
$validations = [
$attribute->code => [$attribute->is_required ? 'required' : 'nullable'],
$attribute->code . '.*.value' => [$attribute->is_required ? 'required' : 'nullable'],
$attribute->code . '.*.value' => [$attribute->is_required ? 'required' : 'nullable', new PhoneNumber],
$attribute->code . '.*.label' => $attribute->is_required ? 'required' : 'nullable',
];
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/WebForm/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@
'delete-success' => 'Web Form deleted successfully.',
'delete-failed' => 'Web Form can not be deleted.',
'submit_button_label' => 'Submit Button Label',
'invalid-phone-number' => 'Invalid phone number',
];
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class="control"
class="control"
v-model="attribute['name']"
/>

<input
type="hidden"
:value="index + 1"
Expand All @@ -304,14 +304,25 @@ class="control"
</td>

<td>
<div class="form-group">
<div
class="form-group"
:class="[errors.has('attributes[' + attribute.id + '][placeholder]') ? 'has-error' : '']"
>
<input
type="text"
:name="'attributes[' + attribute.id + '][placeholder]'"
class="control"
value=""
v-validate="attribute.attribute.validation"
:data-vv-as="attribute['name']"
:placeholder="getPlaceholderValue(attribute)"
/>

<span
class="control-error"
v-if="errors.has('attributes[' + attribute.id + '][placeholder]')"
>
@{{ errors.first('attributes[' + attribute.id + '][placeholder]') }}
</span>
</div>
</td>

Expand All @@ -322,6 +333,8 @@ class="control"
:name="'attributes[' + attribute.id + '][is_required]'"
:id="'is_required_' + attribute.id"
:checked="attribute.is_required"
:disabled="attribute.attribute.is_required ? true : false"
v-model="attribute.is_required"
/>

<label :for="'is_required_' + attribute.id" class="checkbox-view"></label>
Expand All @@ -332,8 +345,7 @@ class="control"
<input
type="hidden"
:name="'attributes[' + attribute.id + '][is_required]'"
value="1"
v-if="attribute.is_required"
:value="attribute.is_required ? 1 : 0"
/>
</td>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ class="control"
:name="'attributes[' + attribute.id + '][is_required]'"
:id="'is_required_' + attribute.id"
:checked="attribute.is_required"
:disabled="attribute.is_required"
:disabled="attribute.attribute.is_required ? true : false"
v-model="attribute.is_required"
/>

<label :for="'is_required_' + attribute.id" class="checkbox-view"></label>
Expand All @@ -440,6 +441,13 @@ class="control"
value="1"
v-if="attribute.is_required"
/>

<input
type="hidden"
:name="'attributes[' + attribute.id + '][is_required]'"
value="0"
v-else
/>
</td>

<td class="delete-icon" style="width: 40px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
class="control"
placeholder="{{ $attribute->placeholder }}"
id="{{ $fieldName }}"
{{ $parentAttribute->is_required ? 'required' : '' }}
{{ $attribute->is_required ? 'required' : '' }}
/>

@break;
Expand All @@ -104,7 +104,7 @@ class="control"
name="{{ $fieldName }}"
class="control"
id="{{ $fieldName }}"
{{ $parentAttribute->is_required ? 'required' : '' }}
{{ $attribute->is_required ? 'required' : '' }}
/>

@break;
Expand All @@ -114,7 +114,7 @@ class="control"
name="{{ $fieldName }}"
class="control"
id="{{ $fieldName }}"
{{ $parentAttribute->is_required ? 'required' : '' }}
{{ $attribute->is_required ? 'required' : '' }}
></textarea>

@break;
Expand All @@ -126,7 +126,7 @@ class="control"
class="control"
placeholder="{{ $attribute->placeholder }}"
id="{{ $fieldName }}"
{{ $parentAttribute->is_required ? 'required' : '' }}
{{ $attribute->is_required ? 'required' : '' }}
/>

<input
Expand All @@ -145,7 +145,7 @@ class="control"
class="control"
placeholder="{{ $attribute->placeholder }}"
id="{{ $fieldName }}"
{{ $parentAttribute->is_required ? 'required' : '' }}
{{ $attribute->is_required ? 'required' : '' }}
/>

<input
Expand All @@ -163,7 +163,7 @@ class="control"
class="control"
id="{{ $fieldName }}"
name="{{ $fieldName }}"
{{ $parentAttribute->is_required ? 'required' : '' }}
{{ $attribute->is_required ? 'required' : '' }}
>
@php
$options = $parentAttribute->lookup_type
Expand Down
33 changes: 33 additions & 0 deletions packages/Webkul/WebForm/src/Rules/PhoneNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Webkul\WebForm\Rules;

use Illuminate\Contracts\Validation\Rule;

class PhoneNumber implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
// This regular expression allows phone numbers with the following conditions:
// - The phone number can start with an optional "+" sign.
// - After the "+" sign, there should be one or more digits.
return preg_match('/^\+?\d+$/', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return __('web_form::app.invalid-phone-number');
}
}

0 comments on commit bde276d

Please sign in to comment.