1023 lines
44 KiB
Text
1023 lines
44 KiB
Text
@model ResponseQuestionnaireViewModel
|
|
@{
|
|
ViewData["Title"] = "DisplayQuestionnaire";
|
|
Layout = "~/Views/Shared/_QuestionnaireResponse.cshtml";
|
|
}
|
|
<style>
|
|
body {
|
|
height: 100% !important;
|
|
background-color: #141c27 !important;
|
|
}
|
|
|
|
|
|
#rowSectionError {
|
|
display: flex;
|
|
flex-wrap: nowrap;
|
|
justify-content: space-around;
|
|
align-items: center;
|
|
align-content: center;
|
|
width: 100%;
|
|
flex-direction: row;
|
|
}
|
|
|
|
|
|
output {
|
|
color: white !important;
|
|
font-weight: bold;
|
|
}
|
|
|
|
#boxBanner {
|
|
display: block;
|
|
width: auto;
|
|
margin: 5px;
|
|
}
|
|
|
|
.QuestionContainer {
|
|
padding-top: 50px;
|
|
padding-bottom: 100px;
|
|
}
|
|
|
|
.stepper {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
}
|
|
|
|
|
|
.step-indicator {
|
|
width: 150px;
|
|
height: 30px;
|
|
border-radius: 3px;
|
|
background-color: transparent;
|
|
margin-bottom: 10px;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
color: white; /* Text color */
|
|
font-weight: bold;
|
|
border: 0.05px solid #294255;
|
|
box-shadow: 0px 0px 6px 2px rgba(0,0,0,0.18);
|
|
-webkit-box-shadow: 0px 0px 6px 2px rgba(0,0,0,0.18);
|
|
-moz-box-shadow: 0px 0px 6px 2px rgba(0,0,0,0.18);
|
|
}
|
|
|
|
.step-indicator.active {
|
|
background-color: #33b3ae; /* Primary color for active step */
|
|
box-shadow: 0px 0px 21px -4px rgba(0,0,0,0.45);
|
|
-webkit-box-shadow: 0px 0px 21px -4px rgba(0,0,0,0.45);
|
|
-moz-box-shadow: 0px 0px 21px -4px rgba(0,0,0,0.45);
|
|
}
|
|
|
|
|
|
h4, h5, h6, p, label {
|
|
color: aliceblue;
|
|
}
|
|
|
|
|
|
|
|
.card {
|
|
box-shadow: 0px 0px 36px -12px rgba(20,101,230,1);
|
|
-webkit-box-shadow: 0px 0px 36px -12px rgba(20,101,230,1);
|
|
-moz-box-shadow: 0px 0px 36px -12px rgba(20,101,230,1);
|
|
border-radius: 10px;
|
|
background-color: transparent;
|
|
padding: 50px;
|
|
}
|
|
|
|
|
|
.form-control {
|
|
width: 80%;
|
|
margin: 15px 0px 0px 0px;
|
|
}
|
|
|
|
|
|
|
|
.hidden-textarea {
|
|
display: none;
|
|
}
|
|
|
|
.rating .rating-item {
|
|
display: inline-block; /* Align items horizontally */
|
|
text-align: center; /* Center-align the label and star */
|
|
margin: 5px; /* Spacing between rating items */
|
|
}
|
|
|
|
.rating .rating-label {
|
|
display: block; /* Ensure the label is on a new line */
|
|
margin-bottom: 2px; /* Space between label and star */
|
|
font-size: 14px; /* Smaller font size for the label */
|
|
color: white;
|
|
}
|
|
|
|
/* Style the stars */
|
|
.rating .rating-star {
|
|
font-size: 24px; /* Adjust size as needed */
|
|
color: #ccc; /* Default color of stars */
|
|
cursor: pointer; /* Change cursor to pointer on hover */
|
|
transition: color 0.3s ease; /* Smooth transition for color change */
|
|
}
|
|
|
|
/* Style the stars when they are hovered over */
|
|
.rating .rating-star:hover,
|
|
.rating .rating-star:hover ~ .rating-star {
|
|
color: #ffe350; /* Color when hovered */
|
|
}
|
|
|
|
/* Style the stars when they are selected */
|
|
.rating .rating-star.selected {
|
|
color: #df9d01; /* Color of selected stars */
|
|
}
|
|
|
|
|
|
|
|
.rank-list {
|
|
list-style-type: none;
|
|
padding: 0;
|
|
}
|
|
|
|
.rank-list li {
|
|
padding: 5px;
|
|
margin-bottom: 2px;
|
|
color: white
|
|
}
|
|
|
|
|
|
.likert {
|
|
box-shadow: 0px 0px 7px 0px rgba(20,101,230,1);
|
|
-moz-box-shadow: 0px 0px 36px -12px rgba(20, 101, 230, 1);
|
|
-webkit-box-shadow: 0px 0px 7px 0px rgba(20,101,230,1);
|
|
border-radius: 5px;
|
|
background-color: transparent;
|
|
padding: 20px;
|
|
}
|
|
|
|
.likert .statement {
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.likert .responses {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.likert .likert-option {
|
|
flex: 1;
|
|
text-align: center;
|
|
}
|
|
|
|
.likert label {
|
|
display: block;
|
|
cursor: pointer;
|
|
padding: 20px;
|
|
background-color: #33b3ae;
|
|
border-radius: 2px;
|
|
margin: 3px;
|
|
transition: background-color 0.3s;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.likert input[type="radio"]:checked + label {
|
|
background-color: transparent;
|
|
color: white;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.card-deck .card {
|
|
cursor: pointer;
|
|
padding: 10px;
|
|
border: 2px solid transparent;
|
|
box-shadow: 0px 0px 36px -12px rgba(20,101,230,1);
|
|
-webkit-box-shadow: 0px 0px 5px 0px rgba(20,101,230,1);
|
|
-moz-box-shadow: 0px 0px 36px -12px rgba(20, 101, 230, 1);
|
|
background-color: transparent;
|
|
transition: border 0.3s ease; /* Add transition for a smooth effect */
|
|
}
|
|
/* img{
|
|
border-radius:3px;
|
|
box-shadow: 0px 0px 36px -12px rgba(20,101,230,1);
|
|
-webkit-box-shadow: 0px 0px 5px 0px rgba(20,101,230,1);
|
|
-moz-box-shadow: 0px 0px 36px -12px rgba(20, 101, 230, 1);
|
|
}
|
|
*/
|
|
.card-deck .card:hover {
|
|
border: 2px solid #007bff;
|
|
transition: border 0.3s ease; /* Ensure the transition applies to the hover state as well */
|
|
}
|
|
|
|
.card-deck .image-card.selected {
|
|
border: 4px solid #28a745; /* Green border for selected cards */
|
|
}
|
|
|
|
.card-deck .image-option {
|
|
display: block;
|
|
}
|
|
|
|
|
|
|
|
.card-deck .image-option input[type="radio"] {
|
|
display: none; /* Hide radio button */
|
|
}
|
|
|
|
.matrix-question .table {
|
|
box-shadow: 0px 0px 7px 0px rgba(20,101,230,1);
|
|
-moz-box-shadow: 0px 0px 36px -12px rgba(20, 101, 230, 1);
|
|
-webkit-box-shadow: 0px 0px 7px 0px rgba(20,101,230,1);
|
|
border-radius: 5px;
|
|
background-color: transparent;
|
|
padding: 20px;
|
|
width: 100%;
|
|
}
|
|
|
|
.matrix-question th, .matrix-question td {
|
|
text-align: left; /* Aligns text to the left */
|
|
border: 2px solid white;
|
|
width: 100%;
|
|
}
|
|
|
|
.matrix-question th {
|
|
background-color: #33b3ae; /* Semi-transparent background for headers */
|
|
color: white; /* White text color for headers */
|
|
}
|
|
|
|
.matrix-question td {
|
|
background-color: #33b3ae; /* Semi-transparent background for headers */
|
|
color: white;
|
|
text-align: left;
|
|
}
|
|
|
|
input[type="radio"] {
|
|
border: 1px solid #007bff !important;
|
|
}
|
|
|
|
.matrix-question input[type="radio"] {
|
|
border: 1px solid #007bff !important;
|
|
}
|
|
|
|
|
|
.sortable-list {
|
|
list-style: none;
|
|
padding: 0;
|
|
}
|
|
|
|
|
|
|
|
.draggable-item:hover {
|
|
background-color: #e0e0e0;
|
|
}
|
|
|
|
button {
|
|
margin-left: 10px;
|
|
}
|
|
|
|
.draggable-item {
|
|
padding: 10px;
|
|
margin-bottom: 5px;
|
|
background-color: #f8f9fa; /* Light gray background for default state */
|
|
border: 1px solid #ccc;
|
|
cursor: grab; /* Cursor indicates that this item is draggable */
|
|
transition: background-color 0.3s ease; /* Smooth transition for background color */
|
|
border-radius: 5px;
|
|
margin: 10px;
|
|
display: flex; /* Enable flexbox */
|
|
align-items: center; /* Center items vertically */
|
|
justify-content: space-between; /* Spread out content */
|
|
}
|
|
|
|
.draggable-item.selected {
|
|
background-color: #33b3ae;
|
|
; /* Blue background for selected state */
|
|
color: white; /* White text color for better visibility */
|
|
}
|
|
|
|
.up-button, .down-button {
|
|
margin: 0 5px; /* Spacing between buttons */
|
|
}
|
|
|
|
.answer-index {
|
|
font-weight: bold;
|
|
}
|
|
|
|
|
|
|
|
|
|
.draggable-item .bi-grip-vertical {
|
|
margin-right: auto; /* Pushes all elements to the right of it to the far right */
|
|
}
|
|
|
|
.draggable-item button {
|
|
margin-left: 5px; /* Space between buttons */
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
<div class="QuestionContainer">
|
|
<section class="hero container card">
|
|
<form id="questionnaireForm" method="post" asp-action="DisplayQuestionnaire">
|
|
<input type="hidden" name="Id" value="@Model.Id">
|
|
<input type="hidden" name="Title" value="@Model.Title">
|
|
<input type="hidden" name="Description" value="@Model.Description">
|
|
|
|
<h4>@Model.Title</h4>
|
|
<p>@Html.Raw(Model.Description)</p>
|
|
<div class="form-group">
|
|
<label for="userName">Your Name:</label>
|
|
<input type="text" class="form-control" id="userName" name="UserName" placeholder="Enter your name">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="Email">Email Address:</label>
|
|
<input type="email" class="form-control" id="Email" name="Email" placeholder="Enter your email">
|
|
</div>
|
|
<div class="container">
|
|
<div class="row align-items-center">
|
|
<!-- Stepper -->
|
|
<div class="col-md-3">
|
|
<div class="stepper">
|
|
@for (int i = 0; i < Model.Questions.Count; i++)
|
|
{
|
|
var question = Model.Questions[i];
|
|
string stepClass = i == 0 ? "active" : ""; // Adjusted the index to start from the first question
|
|
<div class="step-indicator @(stepClass)" data-step-index="@i">
|
|
<span class="step-number">@((i + 1)). </span>
|
|
<span class="step-label">@question.Type</span>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
<!-- Form Content -->
|
|
<div class="col-md-9">
|
|
|
|
@for (int i = 0; i < Model.Questions.Count; i++)
|
|
{
|
|
var question = Model.Questions[i];
|
|
<input type="hidden" name="Id" value="@question.Id">
|
|
<input type="hidden" name="Questions[@i].Text" value="@question.Text">
|
|
<input type="hidden" name="Questions[@i].Id" value="@question.Id">
|
|
<input type="hidden" name="Questions[@i].Type" value="@((int)question.Type)">
|
|
@for (int j = 0; j < question.Answers.Count; j++)
|
|
{
|
|
var answer = question.Answers[j];
|
|
<input type="hidden" name="Questions[@i].Answers[@j].Id" value="@answer.Id">
|
|
<input type="hidden" name="Questions[@i].Answers[@j].Text" value="@answer.Text">
|
|
<!-- Add more hidden fields as needed for other properties of the answer -->
|
|
}
|
|
<div class="step @(i == 0 ? "active" : "")">
|
|
|
|
<p class="font-weight-normal">@(i + 1). @question.Text</p>
|
|
|
|
|
|
|
|
@switch (question.Type)
|
|
{
|
|
case QuestionType.Text:
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
|
|
<input type="Text" class="form-control" id="question@(i + 1)" name="Questions[@i].SelectedText" rows="3" placeholder="Enter answer"></input>
|
|
<input class="form-control hidden-textarea" id="question@(i + 1)" name="Questions[@i].SelectedAnswerIds" value="@answer.Id" rows="3" placeholder="Enter answer" ></input>
|
|
}
|
|
break;
|
|
case QuestionType.CheckBox:
|
|
case QuestionType.Multiple_choice:
|
|
case QuestionType.Demographic:
|
|
|
|
<div class="form-group">
|
|
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
<div class="form-check">
|
|
<input class="form-check-input" id="question@(i)_answer@(answer.Id)" type="checkbox" name="Questions[@i].SelectedAnswerIds" value="@answer.Id" >
|
|
<label class="form-check-label" for="question@(i)_answer@(answer.Id)">
|
|
@answer.Text
|
|
</label>
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
break;
|
|
case QuestionType.TrueFalse:
|
|
<div class="form-check">
|
|
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
<div class="form-check">
|
|
<input class="form-check-input answer-input" type="radio" id="question@(i)_answer@(answer.Id)" name="Questions[@i].SelectedAnswerIds" value="@answer.Id">
|
|
|
|
<label class="form-check-label" for="question@(i)_answer@(answer.Id)">
|
|
@answer.Text
|
|
</label>
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
break;
|
|
case QuestionType.Open_ended:
|
|
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
|
|
<textarea type="Text" class="form-control" id="question@(i + 1)" name="Questions[@i].SelectedText" value="@answer.Text" rows="3" placeholder="Enter answer"></textarea>
|
|
<input type="hidden" class="form-control" id="question@(i + 1)" name="Questions[@i].SelectedAnswerIds" value="@answer.Id" rows="3" placeholder="Enter answer"></input>
|
|
}
|
|
|
|
break;
|
|
|
|
case QuestionType.Slider:
|
|
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
<input type="range" class="form-range " id="question@(i + 1)" name="Questions[@i].SelectedText" min="0" max="100" step="1">
|
|
<input type="hidden" class="form-range " id="question@(i + 1)" name="Questions[@i].SelectedAnswerIds" value="@answer.Id" min="0" max="100" step="1">
|
|
|
|
<output id="question@(i + 1)_output">50</output>
|
|
<script>
|
|
document.getElementById('question@(i + 1)').addEventListener('input', function () {
|
|
document.getElementById('question@(i + 1)_output').value = this.value;
|
|
});
|
|
</script>
|
|
}
|
|
|
|
break;
|
|
case QuestionType.Rating:
|
|
<div class="rating" data-question="@i">
|
|
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
<div class="rating-item">
|
|
<div class="rating-label">@answer.Text</div>
|
|
<input type="radio" id="question@(i)_rating@(answer.Id)"
|
|
name="Questions[@i].SelectedAnswerIds"
|
|
value="@answer.Id" class="rating-input" hidden>
|
|
<label for="question@(i)_rating@(answer.Id)" class="bi bi-star-fill rating-star"></label>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
break;
|
|
case QuestionType.Ranking:
|
|
|
|
<div class="ranking-question">
|
|
<p class="ml-3">drag and drop to move the answers</p>
|
|
<ul class="sortable-list" id="ranking_@question.Id">
|
|
@{
|
|
int index = 1; // Initialize the index to start numbering from 1
|
|
}
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
<li class="draggable-item" draggable="true" id="@answer.Id" ondragstart="dragStart(event);" ondragover="allowDrop(event);" ondrop="drop(event);">
|
|
<span class="answer-index">@index. </span> @answer.Text
|
|
<i class="bi bi-grip-vertical mr-auto"></i>
|
|
<input type="hidden" name="Questions[@i].SelectedAnswerIds" value="@answer.Id">
|
|
<button type="button" class="up-button btn btn-primary btn-sm " onclick="moveUp(this.parentElement)">
|
|
<i class="bi bi-arrow-up"></i> Up
|
|
</button>
|
|
<button type="button" class="down-button btn btn-info btn-sm" onclick="moveDown(this.parentElement)">
|
|
<i class="bi bi-arrow-down"></i> Down
|
|
</button>
|
|
|
|
</li>
|
|
index++; // Increment the index for the next item
|
|
}
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
function allowDrop(ev) {
|
|
ev.preventDefault(); // Necessary to allow a drop event
|
|
}
|
|
|
|
function dragStart(ev) {
|
|
ev.dataTransfer.setData("text", ev.target.id); // Stores the id of the draggable item
|
|
}
|
|
|
|
function drop(ev) {
|
|
ev.preventDefault();
|
|
var data = ev.dataTransfer.getData("text");
|
|
var draggedElement = document.getElementById(data);
|
|
var dropTarget = ev.target.closest('.draggable-item');
|
|
if (dropTarget) {
|
|
var targetRect = dropTarget.getBoundingClientRect();
|
|
var midPoint = targetRect.top + (targetRect.height / 2); // Calculate the midpoint of the drop target
|
|
|
|
var list = dropTarget.parentNode;
|
|
if (ev.clientY < midPoint) {
|
|
// Drop above the target
|
|
list.insertBefore(draggedElement, dropTarget);
|
|
} else {
|
|
// Drop below the target
|
|
if (dropTarget.nextSibling) {
|
|
list.insertBefore(draggedElement, dropTarget.nextSibling);
|
|
} else {
|
|
list.appendChild(draggedElement); // In case the target is the last child
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Click to select item
|
|
document.querySelectorAll('.draggable-item').forEach(item => {
|
|
item.addEventListener('click', function () {
|
|
// Remove previous selections
|
|
removeSelected(this.parentNode);
|
|
// Mark this as selected
|
|
this.classList.add('selected');
|
|
});
|
|
});
|
|
|
|
// Function to remove selected class from siblings
|
|
function removeSelected(parent) {
|
|
parent.querySelectorAll('.draggable-item').forEach(sibling => {
|
|
sibling.classList.remove('selected');
|
|
});
|
|
}
|
|
</script>
|
|
|
|
break;
|
|
|
|
case QuestionType.Likert:
|
|
|
|
<div class="likert">
|
|
|
|
<div class="statement">
|
|
<label>Please indicate your level of agreement with the following statements:</label>
|
|
<div class="responses">
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
<label class="likert-option">
|
|
<input class="form-check-input" type="radio" id="question@(i)_answer@(answer.Id)" name="Questions[@i].SelectedAnswerIds" value="@answer.Id">
|
|
@answer.Text
|
|
</label>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
break;
|
|
case QuestionType.Matrix:
|
|
|
|
<div class="matrix-question">
|
|
<table class="table table-responsive">
|
|
<thead>
|
|
<tr>
|
|
<th>Question</th>
|
|
@foreach (var option in question.Answers) // Assuming these are the consistent answer options across all sub-questions
|
|
{
|
|
<th>@option.Text</th>
|
|
}
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>@question.Text</td>
|
|
@foreach (var option in question.Answers) // Use consistent options for each sub-question
|
|
{
|
|
<td>
|
|
<input type="radio" name="Questions[@i].SelectedAnswerIds" value="@option.Id">
|
|
</td>
|
|
}
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
break;
|
|
case QuestionType.Image:
|
|
|
|
<script>
|
|
|
|
function selectImageCard(answerId, questionId) {
|
|
// Clear previously selected
|
|
var cards = document.querySelectorAll('.image-question[data-question-id="' + questionId + '"] .card');
|
|
cards.forEach(function (card) {
|
|
card.classList.remove('selected');
|
|
});
|
|
|
|
// Set new selected
|
|
var selectedCard = document.getElementById('card_' + answerId);
|
|
selectedCard.classList.add('selected');
|
|
|
|
// Set the radio button as checked
|
|
var radioButton = document.getElementById('image_answer_' + answerId);
|
|
radioButton.checked = true;
|
|
}
|
|
</script>
|
|
|
|
<div class="image-question" data-question-id="@question.Id">
|
|
<div class="card-deck">
|
|
@foreach (var answer in question.Answers)
|
|
{
|
|
<div class="card image-card" id="card_@answer.Id" onclick="selectImageCard('@answer.Id', '@question.Id')">
|
|
<img src="@answer.Text" alt="Image option" class="img-fluid" />
|
|
<input type="radio" id="image_answer_@answer.Id" name="Questions[@i].SelectedAnswerIds" value="@answer.Id" hidden />
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
|
|
break;
|
|
default:
|
|
<div class="alert alert-danger" role="alert">
|
|
Unsupported question type.
|
|
</div>
|
|
break;
|
|
}
|
|
|
|
<div class="mt-3">
|
|
@if (i > 0)
|
|
{
|
|
<button type="button" class="btn btn-secondary btn-sm mr-3 prev" id="BannerButon"><i class="bi bi-arrow-left"></i> Previous </button>
|
|
}
|
|
@if (i < Model.Questions.Count - 1)
|
|
{
|
|
<button type="button" class="btn btn-primary btn-sm next" id="BannerButon">Next <i class="bi bi-arrow-right"></i></button>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
<div class="User-details" style="display:none;">
|
|
<div class="form-group">
|
|
<label for="userName">Your Name:</label>
|
|
<input type="text" class="form-control" id="userName" name="UserName" placeholder="Enter your name" >
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="userEmail">Email Address:</label>
|
|
<input type="email" class="form-control" id="userEmail" name="UserEmail" placeholder="Enter your email" >
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary submit btn-sm mt-4" id="BannerButon">Submit</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
</div>
|
|
|
|
|
|
@section Scripts {
|
|
|
|
|
|
@{
|
|
<partial name="_ValidationScriptsPartial" />
|
|
}
|
|
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
const form = document.getElementById('questionnaireForm');
|
|
if (!form) {
|
|
console.error('Form not found!');
|
|
return;
|
|
}
|
|
$(document).ready(function () {
|
|
$('.rating-item').on('click', function () {
|
|
// Remove 'selected' class from all stars within the same rating
|
|
$(this).siblings().find('.rating-star').removeClass('selected');
|
|
|
|
// Add 'selected' class to the clicked star and all stars before it within the same rating
|
|
$(this).find('.rating-star').addClass('selected');
|
|
$(this).prevAll().find('.rating-star').addClass('selected');
|
|
|
|
// Toggle 'fill' class on the clicked star
|
|
$(this).find('.rating-star').toggleClass('bi-star-fill bi-star');
|
|
|
|
// Check the corresponding radio input
|
|
$(this).find('.rating-input').prop('checked', true);
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Ensure we only add listeners once by checking if they've been added already
|
|
if (!window.hasEventListenersAdded) {
|
|
const upButtons = document.querySelectorAll('.up-button');
|
|
const downButtons = document.querySelectorAll('.down-button');
|
|
|
|
upButtons.forEach(button => {
|
|
button.addEventListener('click', function () {
|
|
moveUp(this);
|
|
});
|
|
});
|
|
|
|
downButtons.forEach(button => {
|
|
button.addEventListener('click', function () {
|
|
moveDown(this);
|
|
});
|
|
});
|
|
|
|
window.hasEventListenersAdded = true; // Set a flag to indicate listeners are added
|
|
}
|
|
function moveUp(button) {
|
|
var li = button.parentNode;
|
|
if (li.previousElementSibling) {
|
|
li.parentNode.insertBefore(li, li.previousElementSibling);
|
|
}
|
|
}
|
|
|
|
function moveDown(button) {
|
|
var li = button.parentNode;
|
|
if (li.nextElementSibling) {
|
|
li.parentNode.insertBefore(li.nextElementSibling, li);
|
|
}
|
|
}
|
|
function updateOrder() {
|
|
document.querySelectorAll('.rank-list').forEach((list, index) => {
|
|
list.querySelectorAll('li').forEach((li, idx) => {
|
|
// Assuming each li has a hidden input as the last child
|
|
li.querySelector('input[type="hidden"]').value = li.getAttribute('data-answer-id');
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
const steps = form.querySelectorAll('.step');
|
|
const stepIndicators = document.querySelectorAll('.step-indicator');
|
|
const submitButton = form.querySelector('.submit');
|
|
let currentStep = 0;
|
|
|
|
// Prevent form submission
|
|
form.addEventListener('submit', function (event) {
|
|
// event.preventDefault();
|
|
console.log('Form submission prevented.');
|
|
|
|
// Here, you can add logic to handle the form data client-side,
|
|
// such as validating input or sending it via AJAX.
|
|
const formData = new FormData(form);
|
|
formData.forEach((value, key) => {
|
|
console.log(`${key}: ${value}`);
|
|
});
|
|
});
|
|
|
|
function showStep(index) {
|
|
steps.forEach((step, i) => {
|
|
step.style.display = i === index ? 'block' : 'none';
|
|
});
|
|
|
|
stepIndicators.forEach((indicator, i) => {
|
|
if (i === index) {
|
|
indicator.classList.add('active');
|
|
} else {
|
|
indicator.classList.remove('active');
|
|
}
|
|
});
|
|
|
|
submitButton.style.display = index === steps.length - 1 ? 'block' : 'none';
|
|
}
|
|
|
|
function goToNextStep() {
|
|
if (currentStep < steps.length - 1) {
|
|
currentStep++;
|
|
showStep(currentStep);
|
|
updateStepper();
|
|
}
|
|
}
|
|
|
|
function goToPrevStep() {
|
|
if (currentStep > 0) {
|
|
currentStep--;
|
|
showStep(currentStep);
|
|
updateStepper();
|
|
}
|
|
}
|
|
|
|
function updateStepper() {
|
|
const currentStepIndex = currentStep;
|
|
stepIndicators.forEach((indicator, i) => {
|
|
indicator.style.backgroundColor = i === currentStepIndex ? '#33b3ae' : ''; // Change to your primary color
|
|
});
|
|
}
|
|
|
|
// Event listeners for next/previous buttons
|
|
const nextButtons = form.querySelectorAll('.next');
|
|
nextButtons.forEach(button => {
|
|
button.addEventListener('click', goToNextStep);
|
|
});
|
|
|
|
const prevButtons = form.querySelectorAll('.prev');
|
|
prevButtons.forEach(button => {
|
|
button.addEventListener('click', goToPrevStep);
|
|
});
|
|
|
|
// Initialize the form at the first step
|
|
showStep(currentStep);
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// document.addEventListener("DOMContentLoaded", function () {
|
|
// const stepper = document.querySelector('.stepper');
|
|
// if (!stepper) {
|
|
// console.error('Stepper not found!');
|
|
// return;
|
|
// }
|
|
|
|
// let shownTypes = new Set(); // Set to track shown question types
|
|
// const stepIndicators = stepper.querySelectorAll('.step-indicator');
|
|
|
|
// stepIndicators.forEach(indicator => {
|
|
// const type = indicator.querySelector('.step-label').textContent.trim(); // Get the text content of the step-label
|
|
// if (shownTypes.has(type)) {
|
|
// // If this type has already been shown, hide this indicator
|
|
// indicator.style.display = 'none';
|
|
// } else {
|
|
// // Otherwise, mark this type as shown
|
|
// shownTypes.add(type);
|
|
// }
|
|
// });
|
|
// });
|
|
</script>
|
|
|
|
@* <script>
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
const form = document.getElementById('questionnaireForm');
|
|
const steps = form.querySelectorAll('.step');
|
|
const stepIndicators = document.querySelectorAll('.step-indicator');
|
|
const submitButton = form.querySelector('.submit');
|
|
let currentStep = 0;
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const form = document.getElementById('questionnaireForm'); // Replace 'myForm' with your actual form ID
|
|
|
|
form.addEventListener('submit', function (event) {
|
|
event.preventDefault(); // Stop the form from submitting
|
|
console.log('Form submission prevented.');
|
|
|
|
// Here, you can add any logic to handle the form data client-side,
|
|
// such as validating input, organizing data, or sending it via AJAX.
|
|
|
|
// Example of gathering form data:
|
|
const formData = new FormData(form);
|
|
formData.forEach((value, key) => {
|
|
console.log(`${key}: ${value}`);
|
|
});
|
|
|
|
// Optionally, you could send the formData using fetch() or another AJAX method
|
|
});
|
|
});
|
|
|
|
|
|
function handleSubmit(event) {
|
|
event.preventDefault(); // Stop the form from submitting normally
|
|
|
|
const form = event.target; // Get the form that triggered the event
|
|
const formData = new FormData(form);
|
|
|
|
// Assuming you need to do something special with `SelectedAnswerIds`
|
|
const refinedFormData = new FormData();
|
|
formData.forEach((value, key) => {
|
|
if (key.includes("SelectedAnswerIds")) {
|
|
document.querySelectorAll(`input[name="${key}"]:checked`).forEach(checkbox => {
|
|
refinedFormData.append(key, checkbox.value); // Only append checked items
|
|
});
|
|
} else {
|
|
refinedFormData.append(key, value); // Append other data normally
|
|
}
|
|
});
|
|
|
|
// Debugging: log formData to ensure it's captured correctly
|
|
console.log('Prepared formData for submission:');
|
|
refinedFormData.forEach((value, key) => {
|
|
console.log(`${key}: ${value}`);
|
|
});
|
|
|
|
// Fetch API to submit the refined FormData
|
|
fetch(form.action, {
|
|
method: 'POST',
|
|
body: refinedFormData,
|
|
})
|
|
.then(response => response.json()) // Assuming JSON response
|
|
.then(data => {
|
|
console.log('Submission successful', data);
|
|
// Handle success (e.g., display a success message, redirect, etc.)
|
|
})
|
|
.catch(error => {
|
|
console.error('Submission failed', error);
|
|
// Handle errors (e.g., display error message)
|
|
});
|
|
}
|
|
|
|
function updateSelectedText(radio, text, index) {
|
|
console.log("Radio checked:", radio.checked); // Check if the radio is indeed checked
|
|
console.log("Text to set:", text); // What text is being set
|
|
console.log("Target hidden input ID:", 'selected_text_question' + index); // Which input we're targeting
|
|
|
|
var hiddenInput = document.getElementById('selected_text_question' + index);
|
|
if (radio.checked) {
|
|
hiddenInput.value = text;
|
|
console.log("Updated hidden input value:", hiddenInput.value); // Verify the value is set
|
|
}
|
|
}
|
|
|
|
function showStep(index) {
|
|
steps.forEach((step, i) => {
|
|
if (i === index) {
|
|
step.style.display = 'block';
|
|
} else {
|
|
step.style.display = 'none';
|
|
}
|
|
});
|
|
|
|
stepIndicators.forEach((indicator, i) => {
|
|
if (i === index) {
|
|
indicator.classList.add('active');
|
|
} else {
|
|
indicator.classList.remove('active');
|
|
}
|
|
});
|
|
|
|
if (index === steps.length - 1) {
|
|
submitButton.style.display = 'block';
|
|
} else {
|
|
submitButton.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
function goToNextStep() {
|
|
if (currentStep < steps.length - 1) {
|
|
currentStep++;
|
|
showStep(currentStep);
|
|
}
|
|
}
|
|
|
|
function goToPrevStep() {
|
|
if (currentStep > 0) {
|
|
currentStep--;
|
|
showStep(currentStep);
|
|
}
|
|
}
|
|
|
|
const nextButtons = form.querySelectorAll('.next');
|
|
nextButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
goToNextStep();
|
|
updateStepper();
|
|
});
|
|
});
|
|
|
|
const prevButtons = form.querySelectorAll('.prev');
|
|
prevButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
goToPrevStep();
|
|
updateStepper();
|
|
});
|
|
});
|
|
|
|
function updateStepper() {
|
|
const currentStepIndex = currentStep;
|
|
stepIndicators.forEach((indicator, i) => {
|
|
if (i === currentStepIndex) {
|
|
indicator.style.backgroundColor = '#33b3ae'; // Change to your primary color
|
|
} else {
|
|
indicator.style.backgroundColor = ''; // Reset to default color for non-active steps
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
showStep(currentStep);
|
|
updateStepper();
|
|
|
|
$('.rating i').on('click', function () {
|
|
var value = $(this).data('value');
|
|
var questionIndex = $(this).closest('.rating').data('question');
|
|
var selectedStars = $(this).closest('.rating').find('i.selected').length;
|
|
|
|
// Unselect all stars
|
|
$(this).closest('.rating').find('i').removeClass('selected');
|
|
|
|
// Select the clicked star and all preceding stars
|
|
$(this).addClass('selected').prevAll().addClass('selected');
|
|
|
|
// Update the hidden input value if needed
|
|
$('input[name="question' + questionIndex + '_rating"]').val(value);
|
|
|
|
// Update the label with the number of selected stars
|
|
$(this).closest('.rating').next('.selected-count').text(selectedStars);
|
|
});
|
|
|
|
// Prevent the default action for the anchor tags within the rating
|
|
$('.rating a').on('click', function (e) {
|
|
e.preventDefault();
|
|
});
|
|
});
|
|
event.preventDefault();
|
|
</script> *@
|
|
|
|
}
|
|
|