Merge pull request #16895 from grokability/fixed_#16863_custom_fields_validation
Fixed #16863 - better handle custom fields validation when unique but not required
This commit is contained in:
@@ -42,12 +42,11 @@ class AssetCheckinController extends Controller
|
||||
return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix'));
|
||||
}
|
||||
|
||||
// Validate custom fields on existing asset
|
||||
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
|
||||
// Invoke the validation to see if the audit will complete successfully
|
||||
$asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect()->route('hardware.edit', $asset)
|
||||
->withErrors($validator);
|
||||
if ($asset->isInvalid()) {
|
||||
return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
|
||||
}
|
||||
|
||||
$target_option = match ($asset->assigned_type) {
|
||||
|
||||
@@ -37,13 +37,13 @@ class AssetCheckoutController extends Controller
|
||||
->with('error', trans('admin/hardware/general.model_invalid_fix'));
|
||||
}
|
||||
|
||||
// Validate custom fields on existing asset
|
||||
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
|
||||
// Invoke the validation to see if the audit will complete successfully
|
||||
$asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect()->route('hardware.edit', $asset)
|
||||
->withErrors($validator);
|
||||
if ($asset->isInvalid()) {
|
||||
return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
|
||||
}
|
||||
|
||||
|
||||
if ($asset->availableForCheckout()) {
|
||||
return view('hardware/checkout', compact('asset'))
|
||||
|
||||
@@ -882,12 +882,12 @@ class AssetsController extends Controller
|
||||
$this->authorize('audit', Asset::class);
|
||||
$settings = Setting::getSettings();
|
||||
|
||||
// Validate custom fields on existing asset
|
||||
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect()->route('hardware.edit', $asset)
|
||||
->withErrors($validator);
|
||||
// Invoke the validation to see if the audit will complete successfully
|
||||
$asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
|
||||
|
||||
if ($asset->isInvalid()) {
|
||||
return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
|
||||
}
|
||||
|
||||
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
||||
|
||||
@@ -113,7 +113,10 @@ class CustomFieldset extends Model
|
||||
$rule[] = 'unique_undeleted';
|
||||
}
|
||||
|
||||
array_push($rule, $field->attributes['format']);
|
||||
if ($field->attributes['format']!='') {
|
||||
array_push($rule, $field->attributes['format']);
|
||||
}
|
||||
|
||||
$rules[$field->db_column_name()] = $rule;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user