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

Added input validation at Property Value assignment #19

Merged
merged 2 commits into from
Aug 13, 2024
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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added modal to display configuration JSON of order items
- Added the Promotions & Coupons CRUD
- Moved the Orders menu item to the top in the Shop section
- Added input validation at Property Value assignment

## 4.1.1
##### 2024-07-23
Expand Down
10 changes: 9 additions & 1 deletion src/Http/Requests/SyncModelPropertyValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SyncModelPropertyValues extends FormRequest implements SyncModelPropertyVa
public function rules()
{
return array_merge($this->getForRules(), [
'propertyValues' => 'sometimes|array'
'propertyValues' => 'sometimes|array',
'propertyValues.*' => 'integer',
]);
}

Expand All @@ -45,4 +46,11 @@ public function authorize()
{
return true;
}

public function messages()
{
return [
'propertyValues.*.integer' => __('Each property value must be a valid entry.'),
];
}
}
27 changes: 26 additions & 1 deletion src/resources/views/product/_show_properties.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,34 @@
</table>
</x-appshell::card>

@if ($errors->any())
@php
$hasPropertyValuesError = false;
$propertyValuesErrorMessage = null;

foreach ($errors->keys() as $key) {
if (Str::startsWith($key, 'propertyValues')) {
$hasPropertyValuesError = true;
$propertyValuesErrorMessage = $errors->first($key);
break;
}
}
@endphp

@if($hasPropertyValuesError)
<script>
document.addEventListener('DOMContentLoaded', function () {
new bootstrap.Modal('#properties-assign-to-model-modal').show();
});
</script>
@endif
@endif

@include('vanilo::property-value.assign._form', [
'for' => shorten(get_class($for)),
'forId' => $for->id,
'assignments' => $for->propertyValues,
'properties' => $properties
'properties' => $properties,
'hasPropertyValuesError' => $hasPropertyValuesError ?? null,
'propertyValuesErrorMessage' => $propertyValuesErrorMessage ?? null,
])
11 changes: 11 additions & 0 deletions src/resources/views/property-value/assign/_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
</button>
</td>
</tr>

@if ($hasPropertyValuesError)
<tr>
<td colspan="3">
<input type="hidden" class="form-control is-invalid">
<div class="invalid-feedback">
{{ $propertyValuesErrorMessage }}
</div>
</td>
</tr>
@endif
</tfoot>
</table>

Expand Down