mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -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;
|
$field = new CustomField;
|
||||||
|
|
||||||
$data = $request->all();
|
$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()) {
|
if ($validator->fails()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $validator->errors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $validator->errors()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,7 +353,7 @@ class CustomField extends Model
|
||||||
* @since [v4.1.10]
|
* @since [v4.1.10]
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function validationRules()
|
public function validationRules($regex_format = null)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
"name" => "required|unique:custom_fields",
|
"name" => "required|unique:custom_fields",
|
||||||
|
@ -362,7 +362,7 @@ class CustomField extends Model
|
||||||
Rule::in(['text', 'listbox', 'textarea', 'checkbox', 'radio'])
|
Rule::in(['text', 'listbox', 'textarea', 'checkbox', 'radio'])
|
||||||
],
|
],
|
||||||
'format' => [
|
'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"
|
'field_encrypted' => "nullable|boolean"
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue