Skip to content

Commit

Permalink
world set up and idea in place
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerrlongg committed Sep 25, 2024
1 parent ba12204 commit 21906d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/AssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Illuminate\Support\Facades\Log;
use \Illuminate\Contracts\View\View;
use \Illuminate\Http\RedirectResponse;
use Illuminate\Support\MessageBag;


/**
Expand All @@ -29,6 +30,7 @@
*/
class AssetModelsController extends Controller
{
protected MessageBag $validatorErrors;
/**
* Returns a view that invokes the ajax tables which actually contains
* the content for the accessories listing, which is generated in getDatatable.
Expand Down Expand Up @@ -158,7 +160,8 @@ public function update(StoreAssetModelRequest $request, $modelId) : RedirectResp

if ($this->shouldAddDefaultValues($request->input())) {
if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))) {
return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error'));
//return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error'));
return redirect()->back()->withErrors($this->validatorErrors);
}
}

Expand Down Expand Up @@ -484,6 +487,7 @@ private function assignCustomFieldsDefaultValues(AssetModel|SnipeModel $model, a
$validator = Validator::make($data, $rules);

if($validator->fails()){
$this->validatorErrors = $validator->messages();
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<span>

<div class="form-group{{ $errors->has('custom_fieldset') ? ' has-error' : '' }}">
<label for="custom_fieldset" class="col-md-3 control-label">
{{ trans('admin/models/general.fieldset') }}
Expand All @@ -22,6 +21,10 @@
@if ($this->fields)

@foreach ($this->fields as $field)
@dump($errors)
@if($errors->has($field->db_column_name()))
"poop"
@endif
<div class="form-group" wire:key="field-{{ $field->id }}">

<label class="col-md-3 control-label{{ $errors->has($field->name) ? ' has-error' : '' }}">{{ $field->name }}</label>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/models/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<!-- Custom Fieldset -->
<!-- If $item->id is null we are cloning the model and we need the $model_id variable -->
@livewire('custom-field-set-default-values-for-model',["model_id" => $item->id ?? $model_id ?? null ])
@livewire('custom-field-set-default-values-for-model', ["model_id" => $item->id ?? $model_id ?? null, "errors" => $errors])

@include ('partials.forms.edit.notes')
@include ('partials.forms.edit.requestable', ['requestable_text' => trans('admin/models/general.requestable')])
Expand Down

0 comments on commit 21906d8

Please sign in to comment.