I am new to the R language. I can't figure out a solution to the problem I am currently facing. I have made a registration page for users. Whenever the user clicks the "submit" button it checks whether the specific conditions are met. If no, then an error message is displayed. Now the problem is that the error message is repeated continuously until the user enters the correct information. It also repeats each time the user clicks the button.
I want the error message to be displayed only once regardless of how many times the user clicks the "submit" button. Also, the error should not repeat when the user is filling the text fields. This might be a stupid question but I would really appreciate some help. I am sharing my code for a better understanding of the problem.
ui <- fluidPage(
tags$style(
type = "text/css",
" .has-error{color: #B31B1B;}"
),
#User Account
div(id ="account", actionBttn("OPEN"," Register",
color = "success", style = "gradient", icon = icon("user"))),
)
# Define server logic
server <- function(input, output) {
#User-Registration Button
observeEvent(input$OPEN,{
showModal(modalDialog( id = "form",
h3(strong("User Sign-Up Portal"), align = "center"),
br(),
textInput("Username", "Enter Username:", value = "", placeholder = "Username"),
textInput("Email", "Enter Email:", value = "", placeholder = "Email"),
passwordInput("Password", "Enter Password:", value = "", placeholder = "Password"),
passwordInput("rePassword", "Retype Password:", value = "", placeholder = "Retype Password"),
easyClose = TRUE,
footer=tagList(
p("Already have an account ? Click to Sign In"),actionButton('signin', 'Sign-In'),
div(style = "margin-right: 300px", actionButton('submit', 'Submit'), actionButton("refresh", "Refresh"),
modalButton('cancel'))
)
)
)
}
)
observeEvent(input$submit,{
urname <- input$Username
uemail <- input$Email
upass <- input$Password
urepass <- input$rePassword
iv <- InputValidator$new()
result = fn$dbGetQuery(con, "Select Username from register where Username = '$urname'")
iv$add_rule("Username", sv_required())
iv$add_rule("Username", ~ if (!isValidFormat(.)) "The username must contain Atleast: 8 characters \n One Upper Case Letter \n One Lower case Character \n One special Character")
iv$add_rule("Username", function(un){
if (count(result) != 0){
"Username already exists. Please enter a unique Username!"
}
})
iv$add_rule("Username", function(unl){
if (str_length(unl) >= 21){
"The Username cannot exceed 20 characters!"
}
})
result1 = fn$dbGetQuery(con, "Select Email from register where Email = '$uemail'")
iv$add_rule("Email", sv_required())
iv$add_rule("Email", ~ if (!isValidEmail(.)) "Not a valid Emai!l")
iv$add_rule("Email", function(ue){
if (count(result1) != 0){
"Email already exists. Please enter a unique Email!"
}
})
iv$add_rule("Password", sv_required())
iv$add_rule("Password", ~ if (!isValidFormat(.)) "The password must contain Atleast: 8 characters \n One Upper Case Letter \n One Lower case Character \n One special Character")
iv$add_rule("Password", function(pass){
if (str_length(pass) <= 7){
"The password should have a minimum of 8 characters!"
}
})
iv$add_rule("Password", function(pass){
if (str_length(pass) >= 13){
"The password should have a maximum of 12 characters!"
}
})
iv$add_rule("rePassword", sv_required())
iv$add_rule("rePassword", function(repass) {
if (repass != upass) {
"Your password and retype password do not match!"
}
})
iv$enable()
req(iv$is_valid())
})