parsley-rails 1.1.13.0 → 1.1.14.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.
@@ -1,5 +1,5 @@
1
1
  module Parsley
2
2
  module Rails
3
- VERSION = "1.1.13.0"
3
+ VERSION = "1.1.14.0"
4
4
  end
5
5
  end
@@ -49,6 +49,35 @@ window.ParsleyConfig = window.ParsleyConfig || {};
49
49
  , afterdate: function ( val, elem, self) {
50
50
  return Date.parse($(elem).val()) < Date.parse(val);
51
51
  }
52
+
53
+ , inlist: function ( val, list, self ) {
54
+ var delimiter = self.options.inlistDelimiter || ',';
55
+ var listItems = (list + "").split(new RegExp("\\s*\\" + delimiter + "\\s*"));
56
+
57
+ return (listItems.indexOf(val.trim()) !== -1);
58
+ }
59
+
60
+ , luhn: function ( val, elem, self) {
61
+ val = val.replace(/[ -]/g, '');
62
+ var digit, n, sum, _j, _len1, _ref2;
63
+ sum = 0;
64
+ _ref2 = val.split('').reverse();
65
+ for (n = _j = 0, _len1 = _ref2.length; _j < _len1; n = ++_j) {
66
+ digit = _ref2[n];
67
+ digit = +digit;
68
+ if (n % 2) {
69
+ digit *= 2;
70
+ if (digit < 10) {
71
+ sum += digit;
72
+ } else {
73
+ sum += digit - 9;
74
+ }
75
+ } else {
76
+ sum += digit;
77
+ }
78
+ }
79
+ return sum % 10 === 0;
80
+ }
52
81
  }
53
82
  , messages: {
54
83
  minwords: "This value should have %s words at least."
@@ -58,6 +87,7 @@ window.ParsleyConfig = window.ParsleyConfig || {};
58
87
  , lessthan: "This value should be less than %s."
59
88
  , beforedate: "This date should be before %s."
60
89
  , afterdate: "This date should be after %s."
90
+ , luhn: "This value should pass the luhn test."
61
91
  }
62
92
  });
63
93
  }(window.jQuery || window.Zepto));
@@ -317,6 +317,12 @@
317
317
  var ParsleyField = function ( element, options, type ) {
318
318
  this.options = options;
319
319
  this.Validator = new Validator( options );
320
+
321
+ // if type is ParsleyFieldMultiple, just return this. used for clone
322
+ if ( type === 'ParsleyFieldMultiple' ) {
323
+ return this;
324
+ }
325
+
320
326
  this.init( element, type || 'ParsleyField' );
321
327
  };
322
328
 
@@ -554,9 +560,7 @@
554
560
  this.$element.addClass( 'parsley-validated' );
555
561
 
556
562
  // remove eventually already binded events
557
- if ( this.$element.data( 'events' ) ) {
558
- this.$element.off( '.' + this.type );
559
- }
563
+ this.$element.off( '.' + this.type );
560
564
 
561
565
  // force add 'change' event if async remote validator here to have result before form submitting
562
566
  if ( this.options.remote && !new RegExp( 'change', 'i' ).test( this.options.trigger ) ) {
@@ -564,14 +568,17 @@
564
568
  }
565
569
 
566
570
  // alaways bind keyup event, for better UX when a field is invalid
567
- var triggers = ( !this.options.trigger ? '' : this.options.trigger + ' ' )
568
- + ( new RegExp( 'key', 'i' ).test( this.options.trigger ) ? '' : 'keyup' );
571
+ var triggers = ( !this.options.trigger ? '' : this.options.trigger )
572
+ + ( new RegExp( 'key', 'i' ).test( this.options.trigger ) ? '' : ' keyup' );
569
573
 
570
574
  // alaways bind change event, for better UX when a select is invalid
571
575
  if ( this.$element.is( 'select' ) ) {
572
576
  triggers += new RegExp( 'change', 'i' ).test( triggers ) ? '' : ' change';
573
577
  }
574
578
 
579
+ // trim triggers to bind them correctly with .on()
580
+ triggers = triggers.replace( /^\s+/g , '' ).replace( /\s+$/g , '' );
581
+
575
582
  this.$element.on( ( triggers + ' ' ).split( ' ' ).join( '.' + this.type + ' ' ), false, $.proxy( this.eventValidation, this ) );
576
583
  }
577
584
 
@@ -824,6 +831,7 @@
824
831
  this.removeErrors();
825
832
  this.validatedOnce = false;
826
833
  this.errorClassHandler.removeClass( this.options.successClass ).removeClass( this.options.errorClass );
834
+
827
835
  return this;
828
836
  }
829
837
 
@@ -890,7 +898,6 @@
890
898
  */
891
899
  , destroy: function () {
892
900
  this.$element.removeClass( 'parsley-validated' );
893
- this.errorClassHandler.removeClass( this.options.errorClass ).removeClass( this.options.successClass );
894
901
  this.reset().$element.off( '.' + this.type ).removeData( this.type );
895
902
  }
896
903
  };
@@ -943,7 +950,7 @@
943
950
  * @param {Object} options
944
951
  */
945
952
  , inherit: function ( element, options ) {
946
- var clone = new ParsleyField( element, options );
953
+ var clone = new ParsleyField( element, options, 'ParsleyFieldMultiple' );
947
954
 
948
955
  for ( var property in clone ) {
949
956
  if ( 'undefined' === typeof this[ property ] ) {
@@ -1005,18 +1012,19 @@
1005
1012
  this.$element.addClass( 'parsley-validated' );
1006
1013
 
1007
1014
  // remove eventually already binded events
1008
- if ( this.$element.data( 'events' ) ) {
1009
- this.$element.off( '.' + this.type );
1010
- }
1015
+ this.$element.off( '.' + this.type );
1011
1016
 
1012
1017
  // alaways bind keyup event, for better UX when a field is invalid
1013
1018
  var self = this
1014
- , triggers = ( !this.options.trigger ? '' : this.options.trigger + ' ' )
1015
- + ( new RegExp( 'change', 'i' ).test( this.options.trigger ) ? '' : 'change' );
1019
+ , triggers = ( !this.options.trigger ? '' : this.options.trigger )
1020
+ + ( new RegExp( 'change', 'i' ).test( this.options.trigger ) ? '' : ' change' );
1021
+
1022
+ // trim triggers to bind them correctly with .on()
1023
+ triggers = triggers.replace( /^\s+/g , '' ).replace( /\s+$/g ,'' );
1016
1024
 
1017
1025
  // bind trigger event on every siblings
1018
1026
  $( this.siblings ).each(function () {
1019
- $( this ).on( triggers.split( ' ' ).join( '.' + self.type + ' ' ), false, $.proxy( self.eventValidation, self ) );
1027
+ $( this ).on( triggers.split( ' ' ).join( '.' + self.type + ' ' ) , false, $.proxy( self.eventValidation, self ) );
1020
1028
  } )
1021
1029
  }
1022
1030
  };
@@ -1139,6 +1147,16 @@
1139
1147
  return isValid;
1140
1148
  }
1141
1149
 
1150
+ , isValid: function () {
1151
+ for ( var item = 0; item < this.items.length; item++ ) {
1152
+ if ( false === this.items[ item ].isFieldValid() ) {
1153
+ return false;
1154
+ }
1155
+ }
1156
+
1157
+ return true;
1158
+ }
1159
+
1142
1160
  /**
1143
1161
  * Remove all errors ul under invalid fields
1144
1162
  *
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsley-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.13.0
4
+ version: 1.1.14.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-01 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Parsley.js bundled for Rails Asset Pipeline
15
15
  email: