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

Fixes #9415 Cannot set regex for Custom Field via API. #9443

Merged
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
9 changes: 8 additions & 1 deletion app/Http/Controllers/Api/CustomFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ public function store(Request $request)
$field = new CustomField;

$data = $request->all();
$validator = Validator::make($data, $field->validationRules());
$regex_format = null;

if (str_contains($data["format"], "regex:")){
$regex_format = $data["format"];
}

$validator = Validator::make($data, $field->validationRules($regex_format));

if ($validator->fails()) {
return response()->json(Helper::formatStandardApiResponse('error', null, $validator->errors()));
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function convertUnicodeDbSlug($original = null)
* @since [v4.1.10]
* @return array
*/
public function validationRules()
public function validationRules($regex_format = null)
{
return [
"name" => "required|unique:custom_fields",
Expand All @@ -362,7 +362,7 @@ public function validationRules()
Rule::in(['text', 'listbox', 'textarea', 'checkbox', 'radio'])
],
'format' => [
Rule::in(array_merge(array_keys(CustomField::PREDEFINED_FORMATS), CustomField::PREDEFINED_FORMATS))
Rule::in(array_merge(array_keys(CustomField::PREDEFINED_FORMATS), CustomField::PREDEFINED_FORMATS, [$regex_format]))
],
'field_encrypted' => "nullable|boolean"
];
Expand Down