Closed tagliala closed 7 years ago
I came up with
# Determine the proper event to listen to
#
# Turbolinks and Turbolinks Classic don't use the same event, so we will try to
# detect Turbolinks Classic by the EVENT hash, which is not defined
# in the new 5.0 version.
window.ClientSideValidations.event =
if window.Turbolinks? and window.Turbolinks.supported
if window.Turbolinks.EVENTS?
'page:change'
else
'turbolinks:load'
else
'ready'
# Main hook
# If new forms are dynamically introduced into the DOM the .validate() method
# must be invoked on that form
$(document).bind window.ClientSideValidations.event, ->
ClientSideValidations.disableValidators()
$(ClientSideValidations.selectors.forms).validate()
Not an English native speaker, so feel free to provide a better comment
Reopening.
This is not so simple
Ref: https://github.com/turbolinks/turbolinks/issues/4 https://github.com/kossnocorp/jquery.turbolinks/issues/56
What are the remaining problems ? Restoring previous pages from session should restore validations ? (From someone who want to add this gem to a rails 5 app)
I'm going to close this because I've fixed the before mentioned issues in version 4.2.4
Turbolinks 5 changed event names, so we need to adjust something in this gem
Current issues
Turbolinks.supported
property which should be checked before setting the right event to listen to, so the current implementation is bugged on browsers which don't support Turbolinks when Turbolinks is loadedturbolinks:load
instead ofpage:change
. Ref: https://github.com/DavyJonesLocker/client_side_validations/issues/645#issuecomment-223821284Approaches
jquery.turbolinks
are active (ready
andpage:load
).rails.validations.jquery
,rails.validations.turbolinks_classic
andrails.validations.turbolinks
) which add the proper event to listen to. Cons: we will break backward compatibility. And CSV is not properly using SemVer, so 👋 ...YOUR IDEA HERE