Permalink
Browse files

Resolves

DavyJonesLocker/client_side_validations-formtastic#8

Don't allow propagation of any events if form is invalid
  • Loading branch information...
1 parent a8c0051 commit fd9f9d078159761e66e67d1a2d6663e3cdd0d878 @bcardarella bcardarella committed Oct 8, 2012
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'thin'
s.add_development_dependency 'json'
s.add_development_dependency 'coffee-script'
+ s.add_development_dependency 'jquery-rails'
end
@@ -133,7 +133,10 @@ window.ClientSideValidations.enablers =
# Set up the events for the form
$form.on(event, binding) for event, binding of {
- 'submit.ClientSideValidations' : (eventData) -> eventData.preventDefault() unless $form.isValid(form.ClientSideValidations.settings.validators)
+ 'submit.ClientSideValidations' : (eventData) ->
+ unless $form.isValid(form.ClientSideValidations.settings.validators)
+ eventData.preventDefault()
+ eventData.stopImmediatePropagation()
'ajax:beforeSend.ClientSideValidations' : (eventData) -> $form.isValid(form.ClientSideValidations.settings.validators) if eventData.target == @
'form:validate:after.ClientSideValidations' : (eventData) -> ClientSideValidations.callbacks.form.after( $form, eventData)
'form:validate:before.ClientSideValidations': (eventData) -> ClientSideValidations.callbacks.form.before($form, eventData)
@@ -107,3 +107,21 @@ test('Resetting client side validations', 9, function() {
ok(input.parent().find('label:contains("must be present")')[0]);
});
+asyncTest('Handle disable-with', 1, function() {
+ var form = $('form#new_user'), input = form.find('input#user_name');
+ var label = $('label[for="user_name"]');
+ form.append($('<input />', {
+ type: 'submit',
+ 'data-disable-with': 'Waiting...',
+ name: 'commit',
+ value: 'Save',
+ id: 'submit_button'
+ }));
+
+ form.trigger('submit');
+ setTimeout(function() {
+ start();
+ ok($('#submit_button').attr('disabled') === undefined)
+ }, 60);
+});
+
@@ -47,6 +47,7 @@ def call(env)
end
use AssetPath, :urls => ['/vendor/assets/javascripts'], :root => File.expand_path('../..', settings.root)
+use AssetPath, :urls => ['/vendor/assets/javascripts'], :root => File.expand_path('../', $:.find { |p| p =~ /jquery-rails/ })
JQUERY_VERSIONS = %w[ 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.7 1.7.1 1.7.2].freeze
@@ -12,6 +12,7 @@
</style>
<%= script_tag jquery_src %>
+ <%= script_tag "/vendor/assets/javascripts/jquery_ujs.js" %>
<%= script_tag "/vendor/assets/javascripts/rails.validations.js" %>
</head>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit fd9f9d0

Please sign in to comment.