juba / shinyglide

Glide.js component for Shiny apps
https://juba.github.io/shinyglide/
91 stars 8 forks source link

Customize Next Button to add validations #8

Open nikhil-nomula opened 4 years ago

nikhil-nomula commented 4 years ago

Hi,

Is it possible to make validations when user clicks on Next and go to next screen only if the validations pass?

juba commented 4 years ago

I'm not sure I understand your request. You would like the button not to be disabled, but the validation to take place when the user clicks Next ? Is there a particular reason you would like this feature ?

nikhil-nomula commented 4 years ago

Ah ok, for e.g. I have a form where user enters, and then when he/she clicks next, what I want to do is in server.ui, perform validations and then display modal if validations fail, if not go to next screen.

Does that make sense?

juba commented 4 years ago

Ah, I think I understand. Unfortunately no, this is not possible right now, if validation fails the "next" button is inactive, there's no way to perform the check at click time. And given the complexity it took to implement the current validation system, I'm not sure I would be able to modify it...

nikhil-nomula commented 4 years ago

Got it, I understand. It is a pretty good package. The workaround I am planning to do is, have an extra button on screen, have user click it and then perform validation, use a reactive variable in server.R and then show the next button in ui.R based on that. That should be possible right?

juba commented 4 years ago

Hmm maybe you could use an hidden input that you would update only if the form is submitted and valid, and add a validation condition on the next button based on this hidden input value ? By using disable_type = hide the next button would be hidden instead of inactive.

samssann commented 4 years ago

I think this feature would be highly appreciated. You could register the following input bindings and functions

input$next_button # observed when next is clicked
input$prev_button # observed when prev is clicked
next() # moves to next screen
prev() # movest to previous screen
input$screen_number # (integer) id of the screen, updates on next() or prev()

Then people could run custom validations e.g.

observeEvent(input$next, {
  if(input$screen_number == 1L) {
     ...
  } else if(input$screen_number == 2L) {
     ...
  }
  next()
})

But yeah, this is essentially the same functionality the package already has (with js), but with maybe a bit more control for the user. Server side validation would be huge.

juba commented 4 years ago

Hm, I see how this could indeed be quite useful, I didn't think of it this way.

I'm reopening the issue and will try to take a look at it (but with no ETA I fear...)

Thanks for the clarification.