From cd50749655967cb9874bc3b23c601ce99d43aca8 Mon Sep 17 00:00:00 2001 From: Pingfan Hu Date: Sat, 5 Oct 2024 10:24:22 -0400 Subject: [PATCH] asterisk logic update --- R/config.R | 16 ++++------------ R/ui.R | 7 ++----- inst/css/surveydown.css | 10 ++++++++++ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/R/config.R b/R/config.R index dc9b3da5..d1e8a60f 100644 --- a/R/config.R +++ b/R/config.R @@ -94,7 +94,7 @@ get_html_content <- function(survey_file) { } extract_html_pages <- function( - html_content, required_questions, all_questions_required, show_if + html_content, required_questions, all_questions_required, show_if ) { pages <- html_content |> rvest::html_elements(".sd-page") |> @@ -110,18 +110,10 @@ extract_html_pages <- function( question_ids <- c(question_ids, question_id) is_required <- all_questions_required | (question_id %in% required_questions) - # Asterisk display - asterisk <- rvest::html_element(container, ".required-asterisk") - if (!is_required) { - xml2::xml_attr(asterisk, "style") <- "display: none;" - } - - # Set the container's position to relative - current_style <- xml2::xml_attr(container, "style") - new_style <- paste(current_style, "position: relative;", sep = " ") - xml2::xml_attr(container, "style") <- new_style - + # Track required questions and display asterisk if (is_required) { + asterisk <- rvest::html_element(container, ".hidden-asterisk") + xml2::xml_attr(asterisk, "style") <- "display: inline;" required_question_ids <- c(required_question_ids, question_id) } diff --git a/R/ui.R b/R/ui.R index 1fdef27d..2b22ee97 100644 --- a/R/ui.R +++ b/R/ui.R @@ -201,11 +201,8 @@ sd_question <- function( # Check if question if answered js_interaction <- sprintf("Shiny.setInputValue('%s_interacted', true, {priority: 'event'});", id) - # Add asterisk to label for all questions - label <- paste0( - label, - " *" - ) + # Initially hide asterisk for all questions + label <- paste0(label," *") if (type == "select") { option <- c("", option) diff --git a/inst/css/surveydown.css b/inst/css/surveydown.css index 184e47dd..0f972bdf 100644 --- a/inst/css/surveydown.css +++ b/inst/css/surveydown.css @@ -66,6 +66,16 @@ p, .form-group, .control-label { width: 100%; } +/* Hidden Asterisk */ +.hidden-asterisk { + display: none; + color: red; + font-size: 1.5em; + position: absolute; + top: 0; + right: 0.5em; +} + /* Radio and Checkbox styling */ .radio-inline, .checkbox-inline,