Skip to content

Commit

Permalink
asterisk logic update
Browse files Browse the repository at this point in the history
  • Loading branch information
pingfan-hu committed Oct 5, 2024
1 parent ffbedb2 commit cd50749
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
16 changes: 4 additions & 12 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") |>
Expand All @@ -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)
}

Expand Down
7 changes: 2 additions & 5 deletions R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
" <span class='required-asterisk' style='display: inline; color: red; font-size: 1.5em; position: absolute; top: 0; right: 0.5em;'>*</span>"
)
# Initially hide asterisk for all questions
label <- paste0(label," <span class='hidden-asterisk'>*</span>")

if (type == "select") {
option <- c("", option)
Expand Down
10 changes: 10 additions & 0 deletions inst/css/surveydown.css
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cd50749

Please sign in to comment.