From f050dd919d5719874aafadf0a674d816a25bc9eb Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 29 Apr 2020 22:11:19 +0530 Subject: Fix: #696 --- yaksh/forms.py | 3 +++ yaksh/models.py | 3 +++ yaksh/static/yaksh/js/add_question.js | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/yaksh/forms.py b/yaksh/forms.py index 216f5c2..1cd1291 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -298,6 +298,9 @@ class QuestionForm(forms.ModelForm): self.fields['language'].widget.attrs.update( {'class': 'custom-select'} ) + self.fields['topic'].widget.attrs.update( + {'class': 'custom-select'} + ) self.fields['type'].widget.attrs.update( {'class': 'custom-select'} ) diff --git a/yaksh/models.py b/yaksh/models.py index 9bcb132..d67a8e3 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -49,6 +49,7 @@ languages = ( ("java", "Java Language"), ("scilab", "Scilab"), ("r", "R"), + ("other", "Other") ) question_types = ( @@ -1292,6 +1293,8 @@ class Question(models.Model): language = models.CharField(max_length=24, choices=languages) + topic = models.CharField(max_length=50, blank=True, null=True) + # The type of question. type = models.CharField(max_length=24, choices=question_types) diff --git a/yaksh/static/yaksh/js/add_question.js b/yaksh/static/yaksh/js/add_question.js index 6cd8b48..1358710 100644 --- a/yaksh/static/yaksh/js/add_question.js +++ b/yaksh/static/yaksh/js/add_question.js @@ -192,3 +192,30 @@ function autosubmit() } } + +$(document).ready(() => { + let option = $('#id_language').val(); + if(option === 'other') { + $('#id_topic').closest('tr').show(); + } else { + $('#id_topic').closest('tr').hide(); + } + $('#id_language').change(function() { + let value = $(this).val(); + if (value === "other") { + $('#id_topic').closest('tr').show(); + $('#id_type').children("option[value='code']").hide(); + } else { + $('#id_topic').closest('tr').hide(); + $('#id_type').children("option[value='code']").show(); + } + }); + $('#id_type').change(function() { + let value = $(this).val(); + if (value === "code") { + $('#id_language').children("option[value='other']").hide(); + } else { + $('#id_language').children("option[value='other']").show(); + } + }) +}); \ No newline at end of file -- cgit