Ürünleri gösterdiğim kısımda ki formu radio butonun seçimine göre gösterip gizlemeye çalışıyorum ama gizlenmiyor.
@extends(BaseHelper::getAdminMasterLayoutTemplate())
@section('style')
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<style>
.select-multiple {
display: none;
}
</style>
@endsection
@section('content')
<div class="container">
<h1>{{ isset($salesRegion) ? __('Satış Bölgesini Düzenle') : __('Yeni Satış Bölgesi') }}</h1>
<form action="{{ isset($salesRegion) ? route('sales.sales_regions.update', $salesRegion->id) : route('sales.sales_regions.store') }}" method="POST">
@csrf
@if(isset($salesRegion))
@method('PUT')
@endif
<div class="form-group">
<label for="name">{{ __('Satış Bölgesi Adı') }}</label>
<input type="text" name="name" id="name" class="form-control" value="{{ old('name', $salesRegion->name ?? '') }}" required>
@error('name')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="sale_area_id">{{ __('Bölge Grubu') }}</label>
<select name="sale_area_id" id="sale_area_id" class="form-control" required>
<option value="">{{ __('Seçin') }}</option>
@foreach($saleAreas as $id => $name)
<option value="{{ $id }}" {{ isset($salesRegion) && $salesRegion->sale_area_id == $id ? 'selected' : '' }}>{{ $name }}</option>
@endforeach
</select>
@error('sale_area_id')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label>{{ __('Ürün Seçimi') }}</label><br>
<input type="radio" name="product_selection" value="all" {{ old('product_selection', $salesRegion->product_selection ?? 'all') == 'all' ? 'checked' : '' }}> {{ __('Tüm Ürünler') }}<br>
<input type="radio" name="product_selection" value="select" {{ old('product_selection', $salesRegion->product_selection ?? '') == 'select' ? 'checked' : '' }}> {{ __('Ürün Seç') }}
@error('product_selection')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group ">
<label for="product_groups">{{ __('Ürün Grupları') }}</label>
<select name="product_groups[]" id="product_groups" class="form-control select-multiple select2" multiple="multiple">
<option value="">{{ __('Seçin') }}</option>
@foreach($products as $id => $name)
<option value="{{ $id }}"
{{ isset($salesRegion) && in_array($id, $salesRegion->product_groups ?? []) ? 'selected' : '' }}>
{{ $name }}
</option>
@endforeach
</select>
@error('product_groups')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="status">{{ __('Durum') }}</label>
<select name="status" id="status" class="form-control" required>
<option value="1" {{ old('status', $salesRegion->status ?? '') == '1' ? 'selected' : '' }}>{{ __('Aktif') }}</option>
<option value="0" {{ old('status', $salesRegion->status ?? '') == '0' ? 'selected' : '' }}>{{ __('Pasif') }}</option>
</select>
@error('status')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="min_order_amount">{{ __('Minimum Sipariş Tutarı') }}</label>
<input type="number" step="0.01" name="min_order_amount" id="min_order_amount" class="form-control" value="{{ old('min_order_amount', $salesRegion->min_order_amount ?? '') }}" required>
@error('min_order_amount')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="distribution_fee">{{ __('Dağıtım Ücreti') }}</label>
<input type="number" step="0.01" name="distribution_fee" id="distribution_fee" class="form-control" value="{{ old('distribution_fee', $salesRegion->distribution_fee ?? '') }}" required>
@error('distribution_fee')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="free_distribution_min_order_amount">{{ __('Ücretsiz Dağıtım Min. Sipariş Tutarı') }}</label>
<input type="number" step="0.01" name="free_distribution_min_order_amount" id="free_distribution_min_order_amount" class="form-control" value="{{ old('free_distribution_min_order_amount', $salesRegion->free_distribution_min_order_amount ?? '') }}" required>
@error('free_distribution_min_order_amount')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="is_default">{{ __('Varsayılan') }}</label>
<input type="checkbox" name="is_default" id="is_default" class="form-control" {{ old('is_default', $salesRegion->is_default ?? false) ? 'checked' : '' }}>
@error('is_default')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<button type="submit" class="btn btn-primary">{{ __('Kaydet') }}</button>
</form>
</div>
@endsection
@section('scripts')
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('.select2').select2({
placeholder: "{{ __('Seçin') }}",
allowClear: true
});
const selectedProductSelection = $('input[name="product_selection"]:checked').val();
toggleProductGroupsSelect(selectedProductSelection);
$('input[name="product_selection"]').on('change', function() {
toggleProductGroupsSelect($(this).val());
});
function toggleProductGroupsSelect(value) {
const productGroupsSelect = $('.select-multiple');
if (value === 'select') {
productGroupsSelect.show();
productGroupsSelect.attr('required', 'required');
} else {
productGroupsSelect.hide();
productGroupsSelect.removeAttr('required');
}
}
});
</script>
@endsection