diff --git a/application/views/forms/create.php b/application/views/forms/create.php
index a413d76..8eefbdd 100644
--- a/application/views/forms/create.php
+++ b/application/views/forms/create.php
@@ -1,19 +1,22 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/assets/css/style.css b/assets/css/style.css
index 8ad164c..81ef217 100644
--- a/assets/css/style.css
+++ b/assets/css/style.css
@@ -18,7 +18,7 @@
display: flex;
flex-direction: column;
height: 100vh; /* Adjust 60px according to the height of your .form_header */
- overflow-y: auto; /* Add scrollbars if content overflows vertically */
+ overflow-y: auto;/* Add scrollbars if content overflows vertically */
}
@@ -298,9 +298,11 @@ tr:nth-child(even) {
box-shadow: rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.05) 0px 4px 6px -2px;
border-radius: 5px;
height: 50px;
+ margin-top:0px;
/* overflow-y: auto; */
}
+
.submit-button{
color: #fff;
background-color: #7349bd;
diff --git a/assets/js/script.js b/assets/js/script.js
index 78b8a8c..1611e1c 100644
--- a/assets/js/script.js
+++ b/assets/js/script.js
@@ -21,7 +21,7 @@ $(document).ready(function() {
var newQuestion = $('#question-template').clone();
newQuestion.removeAttr('id');
newQuestion.attr('data-question-type', 'multiple-choice'); // Set default question type
- newQuestion.find('.question-box_header_question').attr('placeholder', 'Question ' + questionCount);
+ newQuestion.find('.question-box_header_question').attr('placeholder', 'Question ' );
newQuestion.find('.question-box_option-block_option-text').attr('placeholder', 'Option 1');
newQuestion.show(); // Ensure the cloned template is visible
@@ -30,6 +30,11 @@ $(document).ready(function() {
// Scroll to the newly added question and set it as active
setActiveQuestion(newQuestion);
+
+ //update sidebar
+ updateSidebarMarginTop();
+
+
});
// Add new option to a question
@@ -67,8 +72,26 @@ $(document).ready(function() {
// Delete a question
$(document).on('click', '.delete-question', function() {
- $(this).closest('.question-box').next('br').remove();
- $(this).closest('.question-box').remove();
+ questionCount = questionCount - 1;
+ var questionBox = $(this).closest('.question-box');
+ var prevQuestionBox = questionBox.prev('.question-box');
+ var nextQuestionBox = questionBox.next('.question-box');
+
+ questionBox.next('br').remove(); // Remove the adjacent
element
+ questionBox.remove(); // Remove the question box
+
+ if (nextQuestionBox.length) {
+ setActiveQuestion(nextQuestionBox);
+ } else if (prevQuestionBox.length) {
+ setActiveQuestion(prevQuestionBox);
+ } else {
+ // No questions left, align sidebar with form container top
+ setActiveQuestion($([])); // Pass an empty jQuery object
+ }
+
+ //update sidebar
+ updateSidebarMarginTop();
+
});
// Duplicate a question
@@ -122,23 +145,41 @@ $(document).ready(function() {
$('.question-box').removeClass('active');
// Add active class to the clicked question box
- questionBox.addClass('active');
-
- // Scroll the sidebar to the active question
-
- // Move the sidebar beside the active question
- sidebar.css({
- position: 'absolute',
- top: offset,
- right: 0 // Align the sidebar to the right side of its container
- });
+ questionBox.addClass('active');
}
// Add click event listener to all question boxes to set active question
$(document).on('click', '.question-box', function() {
- setActiveQuestion($(this));
+ setActiveQuestion($(this));
+ //update sidebar
+ updateSidebarMarginTop();
});
+ //update Sidebar Margin
+ function updateSidebarMarginTop() {
+ var sidebar = $('.sidebar');
+ var questionCount = $('.question-box').length;
+ var referencePoint = $('.reference-point');
+ var activeQuestionBox = $('.question-box.active');
+
+ if (questionCount === 0) {
+ sidebar.css('margin-top', '0px');
+ } else if (questionCount === 1) {
+ sidebar.css('margin-top', '185px');
+ } else {
+ if (activeQuestionBox.length) {
+ // Calculate the offset of the active question from the reference point
+ var referenceOffsetTop = referencePoint.offset().top;
+ var activeBoxOffsetTop = activeQuestionBox.offset().top;
+ var offsetTop = activeBoxOffsetTop - referenceOffsetTop;
+
+ sidebar.css('margin-top', offsetTop + 'px');
+ }
+ }
+ }
+
+
+
// Submit form
$('#submit-form').click(function() {
var formData = {