Permalink
Browse files

Do not validate disabled inputs

Closes #177
  • Loading branch information...
bcardarella authored and Daniel Kirsch committed Oct 10, 2011
1 parent 65bb21f commit db8d42a0bdace6ef0dd4b8af5bbe4efc47227504
Showing with 31 additions and 1 deletion.
  1. +30 −0 test/javascript/public/test/validateElement.js
  2. +1 −1 vendor/assets/javascripts/rails.validations.js
@@ -235,3 +235,33 @@ test("Don't validate inputs with 'data-validate' that are dynamically set to fal
input.trigger('focusout');
ok(!input.parent().hasClass('field_with_errors'));
});
+
+test("Don't validate disabled inputs", function() {
+ $('#qunit-fixture')
+ .append($('<form />', {
+ action: '/users',
+ 'data-validate': true,
+ method: 'post',
+ id: 'new_user_2'
+ }))
+ .find('form')
+ .append($('<label for="user_2_name">name</label>'))
+ .append($('<input />', {
+ name: 'user_2[name]',
+ id: 'user_2_name',
+ type: 'name',
+ 'data-validate': 'true',
+ disabled: 'disabled'
+ }))
+ clientSideValidations.forms['new_user_2'] = {
+ type: 'ActionView::Helpers::FormBuilder',
+ input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
+ label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
+ validators: { 'user_2[name]':{"presence":{"message": "must be present"}}}
+ }
+ $('form#new_user_2').validate();
+ var form = $('form#new_user_2'), input = form.find('input#user_2_name');
+ input.val('');
+ input.trigger('focusout');
+ ok(!input.parent().hasClass('field_with_errors'));
+});
@@ -24,7 +24,7 @@
.bind('form:validate:pass', function(eventData) { clientSideValidations.callbacks.form.pass( form, eventData); })
// Set up the events for each validatable form element
- .find('[data-validate="true"]:input:not(:radio)')
+ .find('[data-validate="true"]:input:enabled:not(:radio)')
.live('focusout', function () { $(this).isValid(settings.validators); })
.live('change', function () { $(this).data('changed', true); })
// Callbacks

0 comments on commit db8d42a

Please sign in to comment.