rapscallion 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/rapscallion/validations.js +36 -36
- data/lib/rapscallion/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cfeac8718cce596dbbc18fb0a5b4f45e82b8fe6
|
4
|
+
data.tar.gz: 2dac14a100ba87b78b1ab169df807f30dbc7f7b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1151d793fa4ae3ba7242aa251c1446c6096384daa2d4f7e72ba5ad9eef48a1d848d3e65303e57f24de581fb9fedc11d996517cfc7738501e0f3c287a87b57f14
|
7
|
+
data.tar.gz: a053bd7e80b31938b20c87bb70839dccb31f3264054b532eb5a5a8b567a0e001df13bdef311d126fe4192e1b218855d334501fbd9ed93bd4132735de484ff208
|
@@ -8,21 +8,21 @@
|
|
8
8
|
|
9
9
|
*/
|
10
10
|
|
11
|
-
(function($){
|
11
|
+
(function ($) {
|
12
12
|
|
13
|
-
$.fn.rapscallion = function(options){
|
13
|
+
$.fn.rapscallion = function (options) {
|
14
14
|
|
15
15
|
var settings = $.extend({
|
16
|
-
|
16
|
+
|
17
17
|
/* error messages will be shown in a div set the class for that here */
|
18
18
|
error_message_container_class: "error_messages",
|
19
|
-
|
19
|
+
|
20
20
|
/* fields with errors will get a class to indicate errors, change that class name here */
|
21
21
|
field_with_error_class: 'has_error',
|
22
|
-
|
22
|
+
|
23
23
|
/* valid fields will get a class to indicate success, change that class name here */
|
24
24
|
field_valid_class: 'is_valid',
|
25
|
-
|
25
|
+
|
26
26
|
/* error messages will be remove from input container, eg closest(:selector), set that here */
|
27
27
|
field_container: 'div.input',
|
28
28
|
|
@@ -31,43 +31,43 @@
|
|
31
31
|
|
32
32
|
}, options);
|
33
33
|
|
34
|
-
return this.each(function() {
|
35
|
-
|
36
|
-
$(this).on(settings.trigger, function(){
|
34
|
+
return this.each(function () {
|
37
35
|
|
38
|
-
|
36
|
+
$(this).on(settings.trigger, function () {
|
37
|
+
|
38
|
+
/* the input in question */
|
39
39
|
var el = $(this);
|
40
|
-
|
40
|
+
|
41
41
|
/* the form */
|
42
42
|
var form = el.closest('form');
|
43
|
-
|
43
|
+
|
44
44
|
/* model reference from field name eg user from user[username] */
|
45
|
-
var klass = el.prop('name').replace(/\[.*\]/,'');
|
46
|
-
|
45
|
+
var klass = el.prop('name').replace(/\[.*\]/, '');
|
46
|
+
|
47
47
|
/* field name eg username from user[username] */
|
48
|
-
var attr = el.prop('id').replace(klass+"_",'');
|
49
|
-
|
48
|
+
var attr = el.prop('id').replace(klass + "_", '');
|
49
|
+
|
50
50
|
/* field value */
|
51
51
|
var field_val = el.val();
|
52
|
-
|
52
|
+
|
53
53
|
/* set up basic hash for validation */
|
54
|
-
validation_data = {klass: klass, attr: attr, field_val: field_val}
|
54
|
+
validation_data = {klass: klass, attr: attr, field_val: field_val};
|
55
55
|
|
56
56
|
/*
|
57
57
|
confirmation fields are special cases, and add the field to confirm for
|
58
58
|
eg password and password_confirmation
|
59
59
|
*/
|
60
|
-
if(attr.match(/.*_confirmation/)
|
61
|
-
var confirmation_field = attr.replace('_confirmation','');
|
60
|
+
if (attr.match(/.*_confirmation/) !== undefined) {
|
61
|
+
var confirmation_field = attr.replace('_confirmation', '');
|
62
62
|
var confirmation_value = form.find('#' + klass + "_" + confirmation_field).val();
|
63
|
-
}
|
63
|
+
}
|
64
64
|
|
65
65
|
validation_data[confirmation_field] = confirmation_value;
|
66
66
|
|
67
67
|
/* existing record? */
|
68
|
-
if(form.data('existing-record')
|
68
|
+
if (form.data('existing-record') !== undefined) {
|
69
69
|
validation_data['existing_record'] = form.data('existing-record');
|
70
|
-
}
|
70
|
+
}
|
71
71
|
|
72
72
|
/* do ajax request */
|
73
73
|
$.ajax({
|
@@ -76,24 +76,24 @@
|
|
76
76
|
dataType: 'json',
|
77
77
|
data: validation_data,
|
78
78
|
|
79
|
-
success: function(data
|
80
|
-
|
79
|
+
success: function (data) {
|
80
|
+
|
81
81
|
/* remove existing error messages */
|
82
|
-
el.closest(settings.field_container).find('.'+settings.error_message_container_class).remove();
|
83
|
-
|
82
|
+
el.closest(settings.field_container).find('.' + settings.error_message_container_class).remove();
|
83
|
+
el.closest(settings.field_container).find('.errors').remove();
|
84
|
+
|
84
85
|
/* if no errors present field is valid, add is_valid css class */
|
85
|
-
if(data.length
|
86
|
+
if (data.length === 0) {
|
86
87
|
el.removeClass(settings.field_with_error_class).addClass(settings.field_valid_class);
|
87
88
|
|
88
|
-
/* if error present field is not valid, add has_error class to input, and error messages after input */
|
89
|
-
|
89
|
+
/* if error present field is not valid, add has_error class to input, and error messages after input */
|
90
90
|
} else {
|
91
91
|
/* cycle through json response adding errors for each */
|
92
|
-
$.each(
|
92
|
+
$.each(data, function (key, val) {
|
93
93
|
el.after('<div class="' + settings.error_message_container_class + '">' + val + '</div>');
|
94
|
-
el.removeClass(settings.field_valid_class).addClass(settings.field_with_error_class)
|
94
|
+
el.removeClass(settings.field_valid_class).addClass(settings.field_with_error_class);
|
95
95
|
});
|
96
|
-
}
|
96
|
+
} /* end if errors or not */
|
97
97
|
|
98
98
|
} /* end success */
|
99
99
|
|
@@ -101,10 +101,10 @@
|
|
101
101
|
|
102
102
|
|
103
103
|
});
|
104
|
-
|
104
|
+
|
105
105
|
|
106
106
|
});
|
107
|
-
|
108
|
-
|
107
|
+
|
108
|
+
|
109
109
|
};
|
110
110
|
}(jQuery));
|
data/lib/rapscallion/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rapscallion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gordon Isnor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|