client_side_validations 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/client_side_validations.gemspec +4 -16
- data/lib/client_side_validations/action_view/form_builder.rb +31 -79
- data/lib/client_side_validations/action_view/form_helper.rb +59 -24
- data/lib/client_side_validations/active_model/exclusion.rb +14 -2
- data/lib/client_side_validations/active_model/format.rb +21 -0
- data/lib/client_side_validations/active_model/inclusion.rb +13 -2
- data/lib/client_side_validations/active_model/length.rb +4 -2
- data/lib/client_side_validations/active_model/numericality.rb +12 -1
- data/lib/client_side_validations/active_model.rb +100 -14
- data/lib/client_side_validations/active_record/middleware.rb +29 -3
- data/lib/client_side_validations/active_record/uniqueness.rb +4 -3
- data/lib/client_side_validations/active_record.rb +2 -1
- data/lib/client_side_validations/config.rb +9 -0
- data/lib/client_side_validations/core_ext/regexp.rb +1 -2
- data/lib/client_side_validations/generators/rails_validations.rb +15 -0
- data/lib/client_side_validations/generators.rb +12 -0
- data/lib/client_side_validations/middleware.rb +63 -24
- data/lib/client_side_validations/version.rb +1 -1
- data/lib/client_side_validations.rb +2 -2
- data/lib/generators/client_side_validations/copy_assets_generator.rb +58 -0
- data/lib/generators/client_side_validations/install_generator.rb +9 -21
- data/lib/generators/templates/client_side_validations/initializer.rb +2 -2
- data/vendor/assets/javascripts/rails.validations.js +474 -282
- metadata +156 -301
- data/lib/client_side_validations/formtastic.rb +0 -21
- data/lib/client_side_validations/mongo_mapper/middleware.rb +0 -20
- data/lib/client_side_validations/mongo_mapper/uniqueness.rb +0 -28
- data/lib/client_side_validations/mongo_mapper.rb +0 -9
- data/lib/client_side_validations/mongoid/middleware.rb +0 -20
- data/lib/client_side_validations/mongoid/uniqueness.rb +0 -28
- data/lib/client_side_validations/mongoid.rb +0 -9
- data/lib/client_side_validations/simple_form.rb +0 -24
- data/lib/generators/client_side_validations/copy_asset_generator.rb +0 -23
- data/lib/generators/templates/client_side_validations/README.rails.3.0 +0 -6
- data/lib/generators/templates/client_side_validations/README.rails.3.1 +0 -7
- data/test/action_view/cases/helper.rb +0 -176
- data/test/action_view/cases/test_helpers.rb +0 -600
- data/test/action_view/cases/test_legacy_helpers.rb +0 -217
- data/test/action_view/models/comment.rb +0 -35
- data/test/action_view/models/post.rb +0 -35
- data/test/action_view/models.rb +0 -3
- data/test/active_model/cases/helper.rb +0 -4
- data/test/active_model/cases/test_acceptance_validator.rb +0 -16
- data/test/active_model/cases/test_base.rb +0 -11
- data/test/active_model/cases/test_confirmation_validator.rb +0 -16
- data/test/active_model/cases/test_exclusion_validator.rb +0 -20
- data/test/active_model/cases/test_format_validator.rb +0 -21
- data/test/active_model/cases/test_inclusion_validator.rb +0 -21
- data/test/active_model/cases/test_length_validator.rb +0 -61
- data/test/active_model/cases/test_numericality_validator.rb +0 -46
- data/test/active_model/cases/test_presence_validator.rb +0 -16
- data/test/active_model/cases/test_validations.rb +0 -175
- data/test/active_model/models/person.rb +0 -17
- data/test/active_record/cases/helper.rb +0 -12
- data/test/active_record/cases/test_base.rb +0 -11
- data/test/active_record/cases/test_middleware.rb +0 -175
- data/test/active_record/cases/test_uniqueness_validator.rb +0 -50
- data/test/active_record/models/guid.rb +0 -7
- data/test/active_record/models/user.rb +0 -14
- data/test/base_helper.rb +0 -8
- data/test/core_ext/cases/test_core_ext.rb +0 -46
- data/test/formtastic/cases/helper.rb +0 -7
- data/test/formtastic/cases/test_form_builder.rb +0 -11
- data/test/formtastic/cases/test_form_helper.rb +0 -21
- data/test/generators/cases/test_generators.rb +0 -31
- data/test/javascript/config.ru +0 -3
- data/test/javascript/public/test/callbacks/elementAfter.js +0 -54
- data/test/javascript/public/test/callbacks/elementBefore.js +0 -54
- data/test/javascript/public/test/callbacks/elementFail.js +0 -70
- data/test/javascript/public/test/callbacks/elementPass.js +0 -70
- data/test/javascript/public/test/callbacks/formAfter.js +0 -45
- data/test/javascript/public/test/callbacks/formBefore.js +0 -45
- data/test/javascript/public/test/callbacks/formFail.js +0 -51
- data/test/javascript/public/test/callbacks/formPass.js +0 -50
- data/test/javascript/public/test/form_builders/validateForm.js +0 -66
- data/test/javascript/public/test/form_builders/validateFormtastic.js +0 -54
- data/test/javascript/public/test/form_builders/validateNestedForm.js +0 -66
- data/test/javascript/public/test/form_builders/validateSimpleForm.js +0 -57
- data/test/javascript/public/test/settings.js +0 -15
- data/test/javascript/public/test/validateElement.js +0 -179
- data/test/javascript/public/test/validators/acceptance.js +0 -42
- data/test/javascript/public/test/validators/confirmation.js +0 -25
- data/test/javascript/public/test/validators/exclusion.js +0 -41
- data/test/javascript/public/test/validators/format.js +0 -27
- data/test/javascript/public/test/validators/inclusion.js +0 -42
- data/test/javascript/public/test/validators/length.js +0 -76
- data/test/javascript/public/test/validators/numericality.js +0 -142
- data/test/javascript/public/test/validators/presence.js +0 -21
- data/test/javascript/public/test/validators/uniqueness.js +0 -96
- data/test/javascript/public/vendor/jquery.metadata.js +0 -122
- data/test/javascript/public/vendor/qunit.css +0 -196
- data/test/javascript/public/vendor/qunit.js +0 -1374
- data/test/javascript/server.rb +0 -84
- data/test/javascript/views/index.erb +0 -20
- data/test/javascript/views/layout.erb +0 -21
- data/test/middleware/cases/helper.rb +0 -18
- data/test/middleware/cases/test_middleware.rb +0 -8
- data/test/mongo_mapper/cases/helper.rb +0 -9
- data/test/mongo_mapper/cases/test_base.rb +0 -15
- data/test/mongo_mapper/cases/test_middleware.rb +0 -77
- data/test/mongo_mapper/cases/test_uniqueness_validator.rb +0 -50
- data/test/mongo_mapper/models/magazine.rb +0 -11
- data/test/mongoid/cases/helper.rb +0 -16
- data/test/mongoid/cases/test_base.rb +0 -15
- data/test/mongoid/cases/test_middleware.rb +0 -77
- data/test/mongoid/cases/test_uniqueness_validator.rb +0 -49
- data/test/mongoid/models/book.rb +0 -12
- data/test/simple_form/cases/helper.rb +0 -5
- data/test/simple_form/cases/test_form_builder.rb +0 -14
- data/test/simple_form/cases/test_form_helper.rb +0 -24
- data/test/test_loader.rb +0 -6
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
module('Element Validate Before Callback', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {"user[name]":{"{presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<span id="result" />'))
|
|
12
|
-
.append($('<form />', {
|
|
13
|
-
action: '/users',
|
|
14
|
-
'data-validate': true,
|
|
15
|
-
method: 'post',
|
|
16
|
-
id: 'new_user'
|
|
17
|
-
}))
|
|
18
|
-
.find('form')
|
|
19
|
-
.append($('<input />', {
|
|
20
|
-
name: 'user[name]',
|
|
21
|
-
id: 'user_name',
|
|
22
|
-
'data-validate': 'true',
|
|
23
|
-
type: 'text'
|
|
24
|
-
}))
|
|
25
|
-
.append($('<label for="user_name">Name</label>'));
|
|
26
|
-
|
|
27
|
-
clientSideValidations.callbacks.element.before = function(element) {
|
|
28
|
-
$('#result').text('Element Validate Before ' + element.attr('id'));
|
|
29
|
-
}
|
|
30
|
-
$('form#new_user').validate();
|
|
31
|
-
},
|
|
32
|
-
teardown: function() {
|
|
33
|
-
clientSideValidations.callbacks.element.before = function(element, eventData) {}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('runs callback when form element validate', function() {
|
|
38
|
-
var input = $('input');
|
|
39
|
-
|
|
40
|
-
equal($('#result').text(), '');
|
|
41
|
-
|
|
42
|
-
input.trigger('focusout');
|
|
43
|
-
equal($('#result').text(), 'Element Validate Before user_name');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('runs callback when form validates', function() {
|
|
47
|
-
var form = $('form'), input = form.find('input');
|
|
48
|
-
|
|
49
|
-
equal($('#result').text(), '');
|
|
50
|
-
|
|
51
|
-
form.submit();
|
|
52
|
-
equal($('#result').text(), 'Element Validate Before user_name');
|
|
53
|
-
});
|
|
54
|
-
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
module('Element Validate Fail Callback', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {"user[name]":{"presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<span id="result" />'))
|
|
12
|
-
.append($('<form />', {
|
|
13
|
-
action: '/users',
|
|
14
|
-
'data-validate': true,
|
|
15
|
-
method: 'post',
|
|
16
|
-
id: 'new_user'
|
|
17
|
-
}))
|
|
18
|
-
.find('form')
|
|
19
|
-
.append($('<input />', {
|
|
20
|
-
name: 'user[name]',
|
|
21
|
-
id: 'user_name',
|
|
22
|
-
'data-validate': 'true',
|
|
23
|
-
type: 'text'
|
|
24
|
-
}))
|
|
25
|
-
.append($('<label for="user_name">Name</label>'));
|
|
26
|
-
|
|
27
|
-
clientSideValidations.callbacks.element.fail = function(element, message) {
|
|
28
|
-
$('#result').text('Element Validate Fail ' + element.attr('id') + ' ' + message);
|
|
29
|
-
}
|
|
30
|
-
$('form#new_user').validate();
|
|
31
|
-
},
|
|
32
|
-
teardown: function() {
|
|
33
|
-
clientSideValidations.callbacks.element.fail = function(element, message, callback) { callback(); }
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('runs callback when form element validate', function() {
|
|
38
|
-
var input = $('input');
|
|
39
|
-
|
|
40
|
-
equal($('#result').text(), '');
|
|
41
|
-
|
|
42
|
-
input.val('test')
|
|
43
|
-
input.trigger('change');
|
|
44
|
-
input.trigger('focusout');
|
|
45
|
-
equal($('#result').text(), '');
|
|
46
|
-
|
|
47
|
-
input.val('')
|
|
48
|
-
input.trigger('change');
|
|
49
|
-
input.trigger('focusout');
|
|
50
|
-
equal($('#result').text(), 'Element Validate Fail user_name must be present');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('runs callback when form validates', function() {
|
|
54
|
-
var form = $('form'), input = form.find('input');
|
|
55
|
-
|
|
56
|
-
equal($('#result').text(), '');
|
|
57
|
-
|
|
58
|
-
input.val('test')
|
|
59
|
-
input.trigger('change');
|
|
60
|
-
form.trigger('submit');
|
|
61
|
-
|
|
62
|
-
equal($('#result').text(), '');
|
|
63
|
-
|
|
64
|
-
input.val('')
|
|
65
|
-
input.trigger('change');
|
|
66
|
-
form.trigger('submit');
|
|
67
|
-
|
|
68
|
-
equal($('#result').text(), 'Element Validate Fail user_name must be present');
|
|
69
|
-
});
|
|
70
|
-
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
module('Element Validate Pass Callback', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {"user[name]":{"presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<span id="result" />'))
|
|
12
|
-
.append($('<form />', {
|
|
13
|
-
action: '/users',
|
|
14
|
-
'data-validate': true,
|
|
15
|
-
method: 'post',
|
|
16
|
-
id: 'new_user'
|
|
17
|
-
}))
|
|
18
|
-
.find('form')
|
|
19
|
-
.append($('<input />', {
|
|
20
|
-
name: 'user[name]',
|
|
21
|
-
id: 'user_name',
|
|
22
|
-
'data-validate': 'true',
|
|
23
|
-
type: 'text'
|
|
24
|
-
}))
|
|
25
|
-
.append($('<label for="user_name">Name</label>'));
|
|
26
|
-
|
|
27
|
-
clientSideValidations.callbacks.element.pass = function(element) {
|
|
28
|
-
$('#result').text('Element Validate Pass ' + element.attr('id'));
|
|
29
|
-
}
|
|
30
|
-
$('form#new_user').validate();
|
|
31
|
-
},
|
|
32
|
-
teardown: function() {
|
|
33
|
-
clientSideValidations.callbacks.element.pass = function(element, callback) { callback() }
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('runs callback when form element validate', function() {
|
|
38
|
-
var input = $('input');
|
|
39
|
-
|
|
40
|
-
equal($('#result').text(), '');
|
|
41
|
-
|
|
42
|
-
input.val('')
|
|
43
|
-
input.trigger('change');
|
|
44
|
-
input.trigger('focusout');
|
|
45
|
-
equal($('#result').text(), '');
|
|
46
|
-
|
|
47
|
-
input.val('test')
|
|
48
|
-
input.trigger('change');
|
|
49
|
-
input.trigger('focusout');
|
|
50
|
-
equal($('#result').text(), 'Element Validate Pass user_name');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('runs callback when form validates', function() {
|
|
54
|
-
var form = $('form'), input = form.find('input');
|
|
55
|
-
|
|
56
|
-
equal($('#result').text(), '');
|
|
57
|
-
|
|
58
|
-
input.val('')
|
|
59
|
-
input.trigger('change');
|
|
60
|
-
form.trigger('submit');
|
|
61
|
-
|
|
62
|
-
equal($('#result').text(), '');
|
|
63
|
-
|
|
64
|
-
input.val('test')
|
|
65
|
-
input.trigger('change');
|
|
66
|
-
form.trigger('submit');
|
|
67
|
-
|
|
68
|
-
equal($('#result').text(), 'Element Validate Pass user_name');
|
|
69
|
-
});
|
|
70
|
-
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module('Form Validate After Callback', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {"user[name]":{"presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<span id="result" />'))
|
|
12
|
-
.append($('<form />', {
|
|
13
|
-
action: '/users',
|
|
14
|
-
'data-validate': true,
|
|
15
|
-
method: 'post',
|
|
16
|
-
id: 'new_user'
|
|
17
|
-
}))
|
|
18
|
-
.find('form')
|
|
19
|
-
.append($('<input />', {
|
|
20
|
-
name: 'user[name]',
|
|
21
|
-
id: 'user_name',
|
|
22
|
-
'data-validate': 'true',
|
|
23
|
-
type: 'text'
|
|
24
|
-
}))
|
|
25
|
-
.append($('<label for="user_name">Name</label>'));
|
|
26
|
-
|
|
27
|
-
clientSideValidations.callbacks.form.after = function(form, message) {
|
|
28
|
-
$('#result').text('Form Validate After ' + form.attr('id'));
|
|
29
|
-
}
|
|
30
|
-
$('form#new_user').validate();
|
|
31
|
-
},
|
|
32
|
-
teardown: function() {
|
|
33
|
-
clientSideValidations.callbacks.form.after = function(form, eventData) {}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('runs callback', function() {
|
|
38
|
-
var form = $('form'), input = form.find('input');
|
|
39
|
-
|
|
40
|
-
equal($('#result').text(), '');
|
|
41
|
-
|
|
42
|
-
form.submit();
|
|
43
|
-
equal($('#result').text(), 'Form Validate After new_user');
|
|
44
|
-
});
|
|
45
|
-
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module('Form Validate Before Callback', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {"user[name]":{"presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<span id="result" />'))
|
|
12
|
-
.append($('<form />', {
|
|
13
|
-
action: '/users',
|
|
14
|
-
'data-validate': true,
|
|
15
|
-
method: 'post',
|
|
16
|
-
id: 'new_user'
|
|
17
|
-
}))
|
|
18
|
-
.find('form')
|
|
19
|
-
.append($('<input />', {
|
|
20
|
-
name: 'user[name]',
|
|
21
|
-
id: 'user_name',
|
|
22
|
-
'data-validate': 'true',
|
|
23
|
-
type: 'text'
|
|
24
|
-
}))
|
|
25
|
-
.append($('<label for="user_name">Name</label>'));
|
|
26
|
-
|
|
27
|
-
clientSideValidations.callbacks.form.before = function(form, message) {
|
|
28
|
-
$('#result').text('Form Validate Before ' + form.attr('id'));
|
|
29
|
-
}
|
|
30
|
-
$('form#new_user').validate();
|
|
31
|
-
},
|
|
32
|
-
teardown: function() {
|
|
33
|
-
clientSideValidations.callbacks.form.before = function(form, eventData) {}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('runs callback', function() {
|
|
38
|
-
var form = $('form'), input = form.find('input');
|
|
39
|
-
|
|
40
|
-
equal($('#result').text(), '');
|
|
41
|
-
|
|
42
|
-
form.submit();
|
|
43
|
-
equal($('#result').text(), 'Form Validate Before new_user');
|
|
44
|
-
});
|
|
45
|
-
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
module('Form Validate Fail Callback', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {"user[name]":{"presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<span id="result" />'))
|
|
12
|
-
.append($('<form />', {
|
|
13
|
-
action: '/users',
|
|
14
|
-
'data-validate': true,
|
|
15
|
-
method: 'post',
|
|
16
|
-
id: 'new_user'
|
|
17
|
-
}))
|
|
18
|
-
.find('form')
|
|
19
|
-
.append($('<input />', {
|
|
20
|
-
name: 'user[name]',
|
|
21
|
-
id: 'user_name',
|
|
22
|
-
'data-validate': 'true',
|
|
23
|
-
type: 'text'
|
|
24
|
-
}))
|
|
25
|
-
.append($('<label for="user_name">Name</label>'));
|
|
26
|
-
|
|
27
|
-
clientSideValidations.callbacks.form.fail = function(form, message) {
|
|
28
|
-
$('#result').text('Form Validate Fail ' + form.attr('id'));
|
|
29
|
-
}
|
|
30
|
-
$('form#new_user').validate();
|
|
31
|
-
},
|
|
32
|
-
teardown: function() {
|
|
33
|
-
clientSideValidations.callbacks.form.fail = function(form, eventData) {}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('runs callback', function() {
|
|
38
|
-
var form = $('form'), input = form.find('input');
|
|
39
|
-
|
|
40
|
-
equal($('#result').text(), '');
|
|
41
|
-
|
|
42
|
-
form.submit();
|
|
43
|
-
equal($('#result').text(), 'Form Validate Fail new_user');
|
|
44
|
-
|
|
45
|
-
$('#result').text('');
|
|
46
|
-
input.val('test');
|
|
47
|
-
input.trigger('change');
|
|
48
|
-
form.submit();
|
|
49
|
-
equal($('#result').text(), '');
|
|
50
|
-
});
|
|
51
|
-
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module('Form Validate Pass Callback', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {"user[name]":{"presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<span id="result" />'))
|
|
12
|
-
.append($('<form />', {
|
|
13
|
-
action: '/users',
|
|
14
|
-
'data-validate': true,
|
|
15
|
-
method: 'post',
|
|
16
|
-
id: 'new_user'
|
|
17
|
-
}))
|
|
18
|
-
.find('form')
|
|
19
|
-
.append($('<input />', {
|
|
20
|
-
name: 'user[name]',
|
|
21
|
-
id: 'user_name',
|
|
22
|
-
'data-validate': 'true',
|
|
23
|
-
type: 'text'
|
|
24
|
-
}))
|
|
25
|
-
.append($('<label for="user_name">Name</label>'));
|
|
26
|
-
|
|
27
|
-
clientSideValidations.callbacks.form.pass = function(form, message) {
|
|
28
|
-
$('#result').text('Form Validate Pass ' + form.attr('id'));
|
|
29
|
-
}
|
|
30
|
-
$('form#new_user').validate();
|
|
31
|
-
},
|
|
32
|
-
teardown: function() {
|
|
33
|
-
clientSideValidations.callbacks.form.pass = function(form, eventData) {}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('runs callback', function() {
|
|
38
|
-
var form = $('form'), input = form.find('input');
|
|
39
|
-
|
|
40
|
-
equal($('#result').text(), '');
|
|
41
|
-
|
|
42
|
-
form.submit();
|
|
43
|
-
equal($('#result').text(), '');
|
|
44
|
-
|
|
45
|
-
input.val('test');
|
|
46
|
-
input.trigger('change');
|
|
47
|
-
form.submit();
|
|
48
|
-
equal($('#result').text(), 'Form Validate Pass new_user');
|
|
49
|
-
});
|
|
50
|
-
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
module('Validate Form', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {'user[name]':{"presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<form />', {
|
|
12
|
-
action: '/users',
|
|
13
|
-
'data-validate': true,
|
|
14
|
-
method: 'post',
|
|
15
|
-
id: 'new_user'
|
|
16
|
-
}))
|
|
17
|
-
.find('form')
|
|
18
|
-
.append($('<input />', {
|
|
19
|
-
name: 'user[name]',
|
|
20
|
-
id: 'user_name',
|
|
21
|
-
'data-validate': 'true',
|
|
22
|
-
type: 'text'
|
|
23
|
-
}))
|
|
24
|
-
.append($('<label for="user_name">Name</label>'));
|
|
25
|
-
$('form#new_user').validate();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
asyncTest('Validate form with invalid form', 4, function() {
|
|
30
|
-
var form = $('form#new_user'), input = form.find('input#user_name');
|
|
31
|
-
var label = $('label[for="user_name"]');
|
|
32
|
-
|
|
33
|
-
form.trigger('submit');
|
|
34
|
-
setTimeout(function() {
|
|
35
|
-
start();
|
|
36
|
-
ok(input.parent().hasClass('field_with_errors'));
|
|
37
|
-
ok(label.parent().hasClass('field_with_errors'));
|
|
38
|
-
ok(input.parent().find('label:contains("must be present")')[0]);
|
|
39
|
-
ok(!$('iframe').contents().find('p:contains("Form submitted")')[0]);
|
|
40
|
-
}, 30);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
asyncTest('Validate form with valid form', 1, function() {
|
|
44
|
-
var form = $('form#new_user'), input = form.find('input#user_name');
|
|
45
|
-
input.val('Test');
|
|
46
|
-
|
|
47
|
-
form.trigger('submit');
|
|
48
|
-
setTimeout(function() {
|
|
49
|
-
start();
|
|
50
|
-
ok($('iframe').contents().find('p:contains("Form submitted")')[0]);
|
|
51
|
-
}, 30);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
asyncTest('Validate form with an input changed to false', 1, function() {
|
|
55
|
-
var form = $('form#new_user'), input = form.find('input#user_name');
|
|
56
|
-
input.val('Test');
|
|
57
|
-
input.attr('changed', false);
|
|
58
|
-
input.attr('data-valid', true);
|
|
59
|
-
|
|
60
|
-
form.trigger('submit');
|
|
61
|
-
setTimeout(function() {
|
|
62
|
-
start();
|
|
63
|
-
ok($('iframe').contents().find('p:contains("Form submitted")')[0]);
|
|
64
|
-
}, 30);
|
|
65
|
-
});
|
|
66
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
module('Validate Formtastic', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'Formtastic::FormBuilder',
|
|
5
|
-
inline_error_class: 'inline-errors',
|
|
6
|
-
validators: {
|
|
7
|
-
"user[name]":{"presence":{"message": "must be present"}, "format":{"message":"is invalid","with":/\d+/}}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
$('#qunit-fixture')
|
|
12
|
-
.append($('<form />', {
|
|
13
|
-
action: '/users',
|
|
14
|
-
'data-validate': true,
|
|
15
|
-
method: 'post',
|
|
16
|
-
id: 'new_user'
|
|
17
|
-
}))
|
|
18
|
-
.find('form')
|
|
19
|
-
.append('<li />').find('li')
|
|
20
|
-
.append($('<input />', {
|
|
21
|
-
name: 'user[name]',
|
|
22
|
-
id: 'user_name',
|
|
23
|
-
'data-validate': 'true',
|
|
24
|
-
type: 'text'
|
|
25
|
-
}))
|
|
26
|
-
.append($('<label for="user_name">Name</label>'));
|
|
27
|
-
$('form#new_user').validate();
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('Validate error attaching and detaching', function() {
|
|
32
|
-
var form = $('form#new_user'), input = form.find('input#user_name');
|
|
33
|
-
var label = $('label[for="user_name"]');
|
|
34
|
-
|
|
35
|
-
input.trigger('focusout')
|
|
36
|
-
ok(input.parent().hasClass('error'));
|
|
37
|
-
ok(label.parent().hasClass('error'));
|
|
38
|
-
ok(input.parent().find('p.inline-errors:contains("must be present")')[0]);
|
|
39
|
-
|
|
40
|
-
input.val('abc')
|
|
41
|
-
input.trigger('change')
|
|
42
|
-
input.trigger('focusout')
|
|
43
|
-
ok(input.parent().hasClass('error'));
|
|
44
|
-
ok(label.parent().hasClass('error'));
|
|
45
|
-
ok(input.parent().find('p.inline-errors:contains("is invalid")')[0]);
|
|
46
|
-
|
|
47
|
-
input.val('123')
|
|
48
|
-
input.trigger('change')
|
|
49
|
-
input.trigger('focusout')
|
|
50
|
-
ok(!input.parent().hasClass('error'));
|
|
51
|
-
ok(!label.parent().hasClass('error'));
|
|
52
|
-
ok(!input.parent().find('p.inline-errors')[0]);
|
|
53
|
-
});
|
|
54
|
-
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
module('Validate Form', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'NestedForm::Builder',
|
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
|
7
|
-
validators: {'user[name]':{"presence":{"message": "must be present"}}}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$('#qunit-fixture')
|
|
11
|
-
.append($('<form />', {
|
|
12
|
-
action: '/users',
|
|
13
|
-
'data-validate': true,
|
|
14
|
-
method: 'post',
|
|
15
|
-
id: 'new_user'
|
|
16
|
-
}))
|
|
17
|
-
.find('form')
|
|
18
|
-
.append($('<input />', {
|
|
19
|
-
name: 'user[name]',
|
|
20
|
-
id: 'user_name',
|
|
21
|
-
'data-validate': 'true',
|
|
22
|
-
type: 'text'
|
|
23
|
-
}))
|
|
24
|
-
.append($('<label for="user_name">Name</label>'));
|
|
25
|
-
$('form#new_user').validate();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
asyncTest('Validate form with invalid form', 4, function() {
|
|
30
|
-
var form = $('form#new_user'), input = form.find('input#user_name');
|
|
31
|
-
var label = $('label[for="user_name"]');
|
|
32
|
-
|
|
33
|
-
form.trigger('submit');
|
|
34
|
-
setTimeout(function() {
|
|
35
|
-
start();
|
|
36
|
-
ok(input.parent().hasClass('field_with_errors'));
|
|
37
|
-
ok(label.parent().hasClass('field_with_errors'));
|
|
38
|
-
ok(input.parent().find('label:contains("must be present")')[0]);
|
|
39
|
-
ok(!$('iframe').contents().find('p:contains("Form submitted")')[0]);
|
|
40
|
-
}, 30);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
asyncTest('Validate form with valid form', 1, function() {
|
|
44
|
-
var form = $('form#new_user'), input = form.find('input#user_name');
|
|
45
|
-
input.val('Test');
|
|
46
|
-
|
|
47
|
-
form.trigger('submit');
|
|
48
|
-
setTimeout(function() {
|
|
49
|
-
start();
|
|
50
|
-
ok($('iframe').contents().find('p:contains("Form submitted")')[0]);
|
|
51
|
-
}, 30);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
asyncTest('Validate form with an input changed to false', 1, function() {
|
|
55
|
-
var form = $('form#new_user'), input = form.find('input#user_name');
|
|
56
|
-
input.val('Test');
|
|
57
|
-
input.attr('changed', false);
|
|
58
|
-
input.attr('data-valid', true);
|
|
59
|
-
|
|
60
|
-
form.trigger('submit');
|
|
61
|
-
setTimeout(function() {
|
|
62
|
-
start();
|
|
63
|
-
ok($('iframe').contents().find('p:contains("Form submitted")')[0]);
|
|
64
|
-
}, 30);
|
|
65
|
-
});
|
|
66
|
-
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
module('Validate SimpleForm', {
|
|
2
|
-
setup: function() {
|
|
3
|
-
window['new_user'] = {
|
|
4
|
-
type: 'SimpleForm::FormBuilder',
|
|
5
|
-
error_class: 'error',
|
|
6
|
-
error_tag: 'span',
|
|
7
|
-
wrapper_error_class: 'field_with_errors',
|
|
8
|
-
wrapper_tag: 'div',
|
|
9
|
-
validators: {
|
|
10
|
-
"user[name]":{"presence":{"message": "must be present"}, "format":{"message":"is invalid","with":/\d+/}}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
$('#qunit-fixture')
|
|
15
|
-
.append($('<form />', {
|
|
16
|
-
action: '/users',
|
|
17
|
-
'data-validate': true,
|
|
18
|
-
method: 'post',
|
|
19
|
-
id: 'new_user'
|
|
20
|
-
}))
|
|
21
|
-
.find('form')
|
|
22
|
-
.append('<div />').find('div')
|
|
23
|
-
.append($('<input />', {
|
|
24
|
-
name: 'user[name]',
|
|
25
|
-
id: 'user_name',
|
|
26
|
-
'data-validate': 'true',
|
|
27
|
-
type: 'text'
|
|
28
|
-
}))
|
|
29
|
-
.append($('<label for="user_name">Name</label>'));
|
|
30
|
-
$('form#new_user').validate();
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('Validate error attaching and detaching', function() {
|
|
35
|
-
var form = $('form#new_user'), input = form.find('input#user_name');
|
|
36
|
-
var label = $('label[for="user_name"]');
|
|
37
|
-
|
|
38
|
-
input.trigger('focusout');
|
|
39
|
-
ok(input.parent().hasClass('field_with_errors'));
|
|
40
|
-
ok(label.parent().hasClass('field_with_errors'));
|
|
41
|
-
ok(input.parent().find('span.error:contains("must be present")')[0]);
|
|
42
|
-
|
|
43
|
-
input.val('abc')
|
|
44
|
-
input.trigger('change')
|
|
45
|
-
input.trigger('focusout')
|
|
46
|
-
ok(input.parent().hasClass('field_with_errors'));
|
|
47
|
-
ok(label.parent().hasClass('field_with_errors'));
|
|
48
|
-
ok(input.parent().find('span.error:contains("is invalid")')[0]);
|
|
49
|
-
|
|
50
|
-
input.val('123')
|
|
51
|
-
input.trigger('change')
|
|
52
|
-
input.trigger('focusout')
|
|
53
|
-
ok(!input.parent().hasClass('field_with_errors'));
|
|
54
|
-
ok(!label.parent().hasClass('field_with_errors'));
|
|
55
|
-
ok(!input.parent().find('span.error')[0]);
|
|
56
|
-
});
|
|
57
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// hijacks normal form submit; lets it submit to an iframe to prevent
|
|
2
|
-
// navigating away from the test suite
|
|
3
|
-
$(document).bind('submit', function(e) {
|
|
4
|
-
if (!e.isDefaultPrevented()) {
|
|
5
|
-
var form = $(e.target), action = form.attr('action'),
|
|
6
|
-
name = 'form-frame' + jQuery.guid++,
|
|
7
|
-
iframe = $('<iframe name="' + name + '" />');
|
|
8
|
-
|
|
9
|
-
if (action.indexOf('iframe') < 0) form.attr('action', action + '?iframe=true')
|
|
10
|
-
form.attr('target', name);
|
|
11
|
-
$('#qunit-fixture').append(iframe);
|
|
12
|
-
form.trigger('iframe:loading');
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|