Skip to content

Commit

Permalink
Merge pull request bagisto#10516 from shivendra-webkul/issue_10512
Browse files Browse the repository at this point in the history
Fixed issue bagisto#10512
  • Loading branch information
devansh-webkul authored Jan 30, 2025
2 parents b40f451 + c07c435 commit a437f67
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/Webkul/Admin/src/Config/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -1221,11 +1221,11 @@
'title' => 'admin::app.configuration.index.sales.shipping-setting.origin.vat-number',
'type' => 'text',
'channel_based' => true,
'validation' => 'phone',
], [
'name' => 'contact',
'title' => 'admin::app.configuration.index.sales.shipping-setting.origin.contact-number',
'type' => 'text',
'validation' => 'phone',
'channel_based' => true,
], [
'name' => 'bank_details',
Expand Down
27 changes: 24 additions & 3 deletions packages/Webkul/Admin/src/Http/Requests/ConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Webkul\Admin\Http\Requests;

use Webkul\Core\Rules\Decimal;
use Webkul\Core\Rules\PostCode;
use Webkul\Core\Rules\PhoneNumber;
use Illuminate\Foundation\Http\FormRequest;

class ConfigurationForm extends FormRequest
Expand Down Expand Up @@ -31,13 +34,31 @@ public function rules()

// Check delete key exist in the request
if (! $this->has("{$key}.delete")) {
$validation = isset($field['validation']) && $field['validation'] ? $field['validation'] : 'nullable';

return [$key => $validation];
return [$key => $this->getValidationRules($field['validation'] ?? 'nullable')];
}

return [];
})->toArray();
})->toArray();
}

/**
* Transform validation rules into an array and map custom validation rules
*
* @param string|array $validation
* @return array
*/
protected function getValidationRules($validation)
{
$validations = is_array($validation) ? $validation : explode('|', $validation);

return array_map(function ($rule) {
return match ($rule) {
'phone' => new PhoneNumber(),
'postcode' => new PostCode(),
'decimal' => new Decimal(),
default => $rule,
};
}, $validations);
}
}
2 changes: 1 addition & 1 deletion packages/Webkul/Core/src/SystemConfig/ItemField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ItemField
* @var array
*/
protected $veeValidateMappings = [
'min'=> 'min_value',
'min' => 'min_value',
];

/**
Expand Down

0 comments on commit a437f67

Please sign in to comment.