mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Handle regex format when assigned from API (#9443)
This commit is contained in:
parent
e4acf8d795
commit
36bc47c61c
|
@ -95,7 +95,14 @@ class CustomFieldsController extends Controller
|
|||
$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()));
|
||||
}
|
||||
|
|
|
@ -353,7 +353,7 @@ class CustomField extends Model
|
|||
* @since [v4.1.10]
|
||||
* @return array
|
||||
*/
|
||||
public function validationRules()
|
||||
public function validationRules($regex_format = null)
|
||||
{
|
||||
return [
|
||||
"name" => "required|unique:custom_fields",
|
||||
|
@ -362,7 +362,7 @@ class CustomField extends Model
|
|||
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"
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue