Fixed Quiz

This commit is contained in:
m.razaghi
2026-08-07 21:36:48 +03:30
parent bb69e7f953
commit 2d6766760f

View File

@@ -14,14 +14,26 @@
<h6 class="mb-0 text-white">افزودن سوال جدید</h6>
</div>
<div class="card-body">
<!-- 🚨 Display Validation Errors Here 🚨 -->
@if ($errors->any())
<div class="alert alert-danger">
<ul class="mb-0">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ route('quizzes.questions.store', $quiz->id) }}" method="POST">
@csrf
<div class="mb-3">
<label class="form-label">نوع سوال</label>
<select name="type" id="questionTypeSelect" class="form-select" onchange="toggleOptionFields(this.value)">
<option value="multiple_choice">چهار گزینه‌ای (تستی)</option>
<option value="descriptive">تشریحی</option>
<option value="multiple_choice" {{ old('type') == 'multiple_choice' ? 'selected' : '' }}>چهار گزینه‌ای (تستی)</option>
<option value="descriptive" {{ old('type') == 'descriptive' ? 'selected' : '' }}>تشریحی</option>
</select>
</div>
@@ -30,19 +42,21 @@
<select name="subject_id" class="form-select">
<option value="">انتخاب درس (مثلاً: حقوق مدنی)</option>
@foreach($subjects as $subject)
<option value="{{ $subject->id }}">{{ $subject->title }}</option>
<option value="{{ $subject->id }}" {{ old('subject_id') == $subject->id ? 'selected' : '' }}>
{{ $subject->title }}
</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label class="form-label">متن سوال / مسئله حقوقی <span class="text-danger">*</span></label>
<textarea name="question_text" class="form-control" rows="4" required placeholder="صورت سوال یا مسئله حقوقی را وارد کنید..."></textarea>
<textarea name="question_text" class="form-control" rows="4" required placeholder="صورت سوال یا مسئله حقوقی را وارد کنید...">{{ old('question_text') }}</textarea>
</div>
<div class="mb-3">
<label class="form-label">بارم / ضریب سوال</label>
<input type="number" step="0.25" name="score" class="form-control" value="1.00" required>
<input type="number" step="0.25" name="score" class="form-control" value="{{ old('score', '1.00') }}" required>
</div>
<!-- Multiple Choice Options Box -->
@@ -51,9 +65,11 @@
@for($i = 0; $i < 4; $i++)
<div class="input-group mb-2">
<div class="input-group-text">
<input class="form-check-input mt-0" type="radio" name="correct_option" value="{{ $i }}" {{ $i == 0 ? 'checked' : '' }}>
<!-- Keep the correct radio button checked -->
<input class="form-check-input mt-0" type="radio" name="correct_option" value="{{ $i }}" {{ old('correct_option', 0) == $i ? 'checked' : '' }}>
</div>
<input type="text" name="options[]" class="form-control" placeholder="متن گزینه {{ $i + 1 }}">
<!-- Keep the typed option text -->
<input type="text" name="options[]" class="form-control" value="{{ old('options.'.$i) }}" placeholder="متن گزینه {{ $i + 1 }}">
</div>
@endfor
<small class="text-muted d-block mb-3">دکمه رادیویی کنار هر گزینه نشان‌دهنده گزینه صحیح است.</small>
@@ -61,7 +77,7 @@
<div class="mb-3">
<label class="form-label">پاسخ تشریحی و مستندات مواد قانونی</label>
<textarea name="solution_explanation" class="form-control" rows="3" placeholder="توضیح پاسخ، استدلال و مواد قانونی مربوطه..."></textarea>
<textarea name="solution_explanation" class="form-control" rows="3" placeholder="توضیح پاسخ، استدلال و مواد قانونی مربوطه...">{{ old('solution_explanation') }}</textarea>
</div>
<button type="submit" class="btn btn-success w-100">افزودن سوال</button>
@@ -126,8 +142,17 @@
</div>
</div>
</div>
@endsection
@section('scripts')
<script>
// Run this immediately on page load to check if we should hide options
// in case the page reloads with old('type') set to 'descriptive'
document.addEventListener("DOMContentLoaded", function() {
var typeSelect = document.getElementById('questionTypeSelect');
toggleOptionFields(typeSelect.value);
});
function toggleOptionFields(type) {
const container = document.getElementById('optionsContainer');
if (type === 'descriptive') {