Rahul R Kulkarni
Rahul R Kulkarni

Reputation: 167

Rest Button on Click Close in MOdal

i am creating an user registration application which accepts the user inputs like:username,Fullname,Email,contact number.

After clicking create button i am able to display modal message stating user registered . Onclick of close button i want my tabpanel created to reset all the textinput to its original data.

1)Created one tabpanel with title.
2)Created all the input and its types.
3)Created Modal successfully.
4)Even tried with shinyjs::reset() funtion as well.

Code for Ui.R:

tabPanel(title="User Management",id ="user",shinyjs::useShinyjs(),
       fluidRow(
               column(5,textInput("uname","User Name")),
               column(5,textInput("fname","Full Name"))),
       fluidRow(
                column(5,textInput("email","Email Id")),
                column(5,numericInput("contactnum","Contactnumber",value=NULL))),
        fluidRow(
                column(5,selectInput("country", label = "Country:",
                                      choices = list("India","USA"), 
                                      selected = 1)),
                column(5,selectInput("state", label = "State:",
                                      choices =list("Karnataka","Kerala"), 
                                      selected = 1))),
        fluidRow(column(5,numericInput("zip","ZIP Code",value=NULL)),
        fluidRow(
                  column(5,passwordInput("pwd1","Password")),
                  column(5,passwordInput("pwd2","Confirm Password"))),
        fluidRow(
                  column(12,actionButton("userCreate", "Create User"), 
                  style="color: #fff; 
                  background-color: #337ab7; border-color: #2e6da4"))),
                       br(),
              )
     )

Server.R:

observeEvent(input$userCreate,{
if(postuser() == 200)
{
  showModal(modalDialog(
    title = "Success",
    "User is successfully added!"
   footer = tagList(
        actionButton("Close", "Close")
      )
    )))
}
})

observeEvent(input$Close,{
 reset("user")
}
)

Update and Tries:

Even tried with shinyjs::reset("user") funtion and shinyjs::js$reset("user")function as well.

Please help me out with this . And i need logical code for list of all the counties and states.

Thanks in Advance

Upvotes: 0

Views: 168

Answers (1)

A. Suliman
A. Suliman

Reputation: 13125

Try

observeEvent(input$Close,{
     #reset("user")
     shinyjs::reset("uname")
     shinyjs::reset("fname")  
     #the remaining fields id's you would like to reset
}

The problem was giving the wrong div id's to reset, hence nothing happened after click close. To understand what I'm talking about have a look at

print(tabPanel(title="User Management",id ="user",shinyjs::useShinyjs(),
                  fluidRow(
                      column(5,textInput("uname","User Name")),
                      column(5,textInput("fname","Full Name")))))

Upvotes: 1

Related Questions