Fixed Quiz
This commit is contained in:
@@ -14,14 +14,26 @@
|
|||||||
<h6 class="mb-0 text-white">افزودن سوال جدید</h6>
|
<h6 class="mb-0 text-white">افزودن سوال جدید</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<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">
|
<form action="{{ route('quizzes.questions.store', $quiz->id) }}" method="POST">
|
||||||
@csrf
|
@csrf
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">نوع سوال</label>
|
<label class="form-label">نوع سوال</label>
|
||||||
<select name="type" id="questionTypeSelect" class="form-select" onchange="toggleOptionFields(this.value)">
|
<select name="type" id="questionTypeSelect" class="form-select" onchange="toggleOptionFields(this.value)">
|
||||||
<option value="multiple_choice">چهار گزینهای (تستی)</option>
|
<option value="multiple_choice" {{ old('type') == 'multiple_choice' ? 'selected' : '' }}>چهار گزینهای (تستی)</option>
|
||||||
<option value="descriptive">تشریحی</option>
|
<option value="descriptive" {{ old('type') == 'descriptive' ? 'selected' : '' }}>تشریحی</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -30,19 +42,21 @@
|
|||||||
<select name="subject_id" class="form-select">
|
<select name="subject_id" class="form-select">
|
||||||
<option value="">انتخاب درس (مثلاً: حقوق مدنی)</option>
|
<option value="">انتخاب درس (مثلاً: حقوق مدنی)</option>
|
||||||
@foreach($subjects as $subject)
|
@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
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">متن سوال / مسئله حقوقی <span class="text-danger">*</span></label>
|
<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>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">بارم / ضریب سوال</label>
|
<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>
|
</div>
|
||||||
|
|
||||||
<!-- Multiple Choice Options Box -->
|
<!-- Multiple Choice Options Box -->
|
||||||
@@ -51,9 +65,11 @@
|
|||||||
@for($i = 0; $i < 4; $i++)
|
@for($i = 0; $i < 4; $i++)
|
||||||
<div class="input-group mb-2">
|
<div class="input-group mb-2">
|
||||||
<div class="input-group-text">
|
<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>
|
</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>
|
</div>
|
||||||
@endfor
|
@endfor
|
||||||
<small class="text-muted d-block mb-3">دکمه رادیویی کنار هر گزینه نشاندهنده گزینه صحیح است.</small>
|
<small class="text-muted d-block mb-3">دکمه رادیویی کنار هر گزینه نشاندهنده گزینه صحیح است.</small>
|
||||||
@@ -61,7 +77,7 @@
|
|||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">پاسخ تشریحی و مستندات مواد قانونی</label>
|
<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>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-success w-100">افزودن سوال</button>
|
<button type="submit" class="btn btn-success w-100">افزودن سوال</button>
|
||||||
@@ -126,8 +142,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('scripts')
|
||||||
<script>
|
<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) {
|
function toggleOptionFields(type) {
|
||||||
const container = document.getElementById('optionsContainer');
|
const container = document.getElementById('optionsContainer');
|
||||||
if (type === 'descriptive') {
|
if (type === 'descriptive') {
|
||||||
|
|||||||
Reference in New Issue
Block a user