parsley-rails 1.2.2.0 → 1.2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cce5a692360a7f3e0184fec2322fa8611804ea3c
4
- data.tar.gz: 0ee0b8ba690ccb71cc828932fe4f7d14290c1cd9
3
+ metadata.gz: b803efc7682990aa6b68daddd2f09ab30fe13f1c
4
+ data.tar.gz: 43958f4da579b5c072c1c5268247473b2a1013e9
5
5
  SHA512:
6
- metadata.gz: 269f14157f1e12e880f47bc27ceb6808155ef89812c11a3c7a91b5b09d2f61fd4e0ed8dacb468f7f01aabb9bc654179c70735060e957d4ec11cdf3db051ce16b
7
- data.tar.gz: 6dcd3d3785654261b383f066de01eadc1a58732ca90067ba0fd4d8d230a4ab1b21b8b74673338b50a7b8c7222d4d00a6c1abd3f967e6f6ba73725cf907e9796d
6
+ metadata.gz: c965240ced0d02f08c6271d1ed225add012fd15542e804d70a1697b8dce92613aace55b7767a54c776985acfe9073890fdd9899c6e274f378e61c9014b1c9c4c
7
+ data.tar.gz: 7135a111f2e713dc2ac92a32d279aa15d19a7841a1bc808c7c392504237d6b16d4ea12ccda55014bb57250a775f6f3a24f4413cff3b0ee4bf3a23946f3006114
@@ -1,5 +1,5 @@
1
1
  module Parsley
2
2
  module Rails
3
- VERSION = "1.2.2.0"
3
+ VERSION = "1.2.3.0"
4
4
  end
5
5
  end
@@ -80,7 +80,7 @@ window.ParsleyConfig = window.ParsleyConfig || {};
80
80
  var delimiter = self.options.inlistDelimiter || ',';
81
81
  var listItems = (list + "").split(new RegExp("\\s*\\" + delimiter + "\\s*"));
82
82
 
83
- return (listItems.indexOf(val.trim()) !== -1);
83
+ return ($.inArray($.trim(val), listItems) !== -1);
84
84
  }
85
85
  , priority: 32
86
86
  }
@@ -0,0 +1,44 @@
1
+ window.ParsleyConfig = window.ParsleyConfig || {};
2
+
3
+ (function ($) {
4
+ window.ParsleyConfig = $.extend( true, {}, window.ParsleyConfig, {
5
+ messages: {
6
+ // parsley //////////////////////////////////////
7
+ defaultMessage: "ค่านี้ดูเหมือนว่าจะไม่ถูกต้อง"
8
+ , type: {
9
+ email: "ค่านี้ควรจะเป็นอีเมลที่ถูกต้อง"
10
+ , url: "ค่านี้ควรจะเป็น url ที่ถูกต้อง"
11
+ , urlstrict: "ค่านี้ควรจะเป็น url ที่ถูกต้อง"
12
+ , number: "ค่านี้ควรจะเป็นตัวเลขที่ถูกต้อง"
13
+ , digits: "ค่านี้ควรจะเป็นเลขโดด"
14
+ , dateIso: "ค่านี้ควรจะเป็นวันที่ที่ถูกต้อง (YYYY-MM-DD)"
15
+ , alphanum: "ค่านี้ควรจะเป็นตัวอักษรเลข"
16
+ , phone: "ค่านี้ควรจะเป็นหมายเลขโทรศัพท์ที่ถูกต้อง"
17
+ }
18
+ , notnull: "ค่านี้ไม่ควรจะไม่มีค่า"
19
+ , notblank: "ค่านี้ไม่ควรจะว่าง"
20
+ , required: "ค่านี้จำเป็น"
21
+ , regexp: "ค่านี้ดูเหมือนว่าจะไม่ถูกต้อง"
22
+ , min: "ค่านี้ควรจะมากกว่าหรือเท่ากับ %s"
23
+ , max: "ค่านี้ควรจะน้อยกว่าหรือเท่ากับ %s"
24
+ , range: "ค่านี้ควรอยู่ระหว่าง %s และ %s"
25
+ , minlength: "ค่านี้สั้นเกินไป, ควรมี %s อักขระหรือมากกว่า"
26
+ , maxlength: "ค่านี้ยาวเกินไป, ควรมี %s อักขระหรือน้อยกว่า"
27
+ , rangelength: "ความยาวของค่านี้ไม่ถูกต้อง, ควรมีความยาวอักขระระหว่าง %s และ %s"
28
+ , mincheck: "คุณจะต้องเลือกอย่างน้อย %s ตัวเลือก"
29
+ , maxcheck: "คุณจะต้องเลือก %s ตัวเลือกหรือน้อยกว่า"
30
+ , rangecheck: "คุณจะต้องเลือกระหว่าง %s และ %s ตัวเลือก"
31
+ , equalto: "ค่านี้ควรจะมีค่าเหมือนกัน"
32
+
33
+ // parsley.extend ///////////////////////////////
34
+ , minwords: "ค่านี้ควรมีจำนวนคำอย่างน้อย %s คำ"
35
+ , maxwords: "่คานี้ควรมีจำนวนคำไม่เกิน %s คำ"
36
+ , rangewords: "ค่านี้ควรอยู่ระหว่าง %s และ %s คำ"
37
+ , greaterthan: "ค่านี้ควรมากกว่า %s"
38
+ , lessthan: "ค่านี้ควรน้อยกว่า %s"
39
+ , beforedate: "วันที่นี้ควรก่อน %s"
40
+ , afterdate: "วันที่นี้ควรหลัง %s"
41
+ , americandate: "ค่านี้ควรเป็นวันที่ที่ถูกต้อง (MM/DD/YYYY)"
42
+ }
43
+ });
44
+ }(window.jQuery || window.Zepto));
@@ -424,7 +424,8 @@
424
424
  * Remove li / ul error
425
425
  *
426
426
  * @method removeError
427
- * @param {String} constraintName Method Name
427
+ * @param {String} constraintName Method Name
428
+ * @return ParsleyUI
428
429
  */
429
430
  , removeError: function ( constraintName ) {
430
431
  var liError = this.ulError + ' .' + constraintName
@@ -436,13 +437,16 @@
436
437
  if ( that.ulError && $( that.ulError ).children().length === 0 ) {
437
438
  that.removeErrors();
438
439
  } } ) : $( liError ).remove();
440
+
441
+ return this;
439
442
  }
440
443
 
441
444
  /**
442
445
  * Add li error
443
446
  *
444
447
  * @method addError
445
- * @param {Object} { minlength: "error message for minlength constraint" }
448
+ * @param {Object} { minlength: "error message for minlength constraint" }
449
+ * @return ParsleyUI
446
450
  */
447
451
  , addError: function ( error ) {
448
452
  for ( var constraint in error ) {
@@ -450,21 +454,44 @@
450
454
 
451
455
  $( this.ulError ).append( this.options.animate ? $( liTemplate ).html( error[ constraint ] ).hide().fadeIn( this.options.animateDuration ) : $( liTemplate ).html( error[ constraint ] ) );
452
456
  }
457
+
458
+ return this;
459
+ }
460
+
461
+ /**
462
+ * Update existing error if text has changed
463
+ *
464
+ * @method updateError
465
+ * @param {Object} { minlength: "error message for minlength constraint" }
466
+ * @return ParsleyUI
467
+ */
468
+ , updateError: function ( error ) {
469
+ for ( var constraint in error ) {
470
+ if ( error[ constraint ] !== $( this.ulError + " > li." + constraint ).html() ) {
471
+ this.removeError( constraint ).addError( error );
472
+ }
473
+ }
474
+
475
+ return this;
453
476
  }
454
477
 
455
478
  /**
456
479
  * Remove all ul / li errors
457
480
  *
458
481
  * @method removeErrors
482
+ * @return ParsleyUI
459
483
  */
460
484
  , removeErrors: function () {
461
485
  this.options.animate ? $( this.ulError ).fadeOut( this.options.animateDuration, function () { $( this ).remove(); } ) : $( this.ulError ).remove();
486
+
487
+ return this;
462
488
  }
463
489
 
464
490
  /**
465
491
  * Remove ul errors and parsley error or success classes
466
492
  *
467
493
  * @method reset
494
+ * @return ParsleyUI
468
495
  */
469
496
  , reset: function () {
470
497
  this.ParsleyInstance.valid = null;
@@ -483,7 +510,8 @@
483
510
  * Add li / ul errors messages
484
511
  *
485
512
  * @method manageError
486
- * @param {Object} constraint
513
+ * @param {Object} constraint
514
+ * @return ParsleyUI
487
515
  */
488
516
  , manageError: function ( constraint ) {
489
517
  // display ulError container if it has been removed previously (or never shown)
@@ -494,11 +522,13 @@
494
522
  // TODO: refacto properly
495
523
  // if required constraint but field is not null, do not display
496
524
  if ( 'required' === constraint.name && null !== this.ParsleyInstance.getVal() && this.ParsleyInstance.getVal().length > 0 ) {
497
- return;
525
+ return this;
526
+
498
527
  // if empty required field and non required constraint fails, do not display
499
528
  } else if ( this.ParsleyInstance.isRequired && 'required' !== constraint.name && ( null === this.ParsleyInstance.getVal() || 0 === this.ParsleyInstance.getVal().length ) ) {
500
529
  this.removeError( constraint.name );
501
- return;
530
+
531
+ return this;
502
532
  }
503
533
 
504
534
  // TODO: refacto error name w/ proper & readable function
@@ -509,17 +539,19 @@
509
539
  this.ParsleyInstance.Validator.messages[ constraintName ][ constraint.requirements ] : ( 'undefined' === typeof this.ParsleyInstance.Validator.messages[ constraintName ] ?
510
540
  this.ParsleyInstance.Validator.messages.defaultMessage : this.ParsleyInstance.Validator.formatMesssage( this.ParsleyInstance.Validator.messages[ constraintName ], constraint.requirements ) ) );
511
541
 
512
- // add liError if not shown. Do not add more than once custom errorMessage if exist
513
- if ( !$( this.ulError + ' .' + liClass ).length ) {
514
- liError[ liClass ] = message;
515
- this.addError( liError );
516
- }
542
+ liError[ liClass ] = message;
543
+
544
+ // add liError if not shown. update if already exist
545
+ !$( this.ulError + ' .' + liClass ).length ? this.addError( liError ) : this.updateError( liError );
546
+
547
+ return this;
517
548
  }
518
549
 
519
550
  /**
520
551
  * Create ul error container
521
552
  *
522
553
  * @method manageErrorContainer
554
+ * @return ParsleyUI
523
555
  */
524
556
  , manageErrorContainer: function () {
525
557
  var errorContainer = this.options.errorContainer || this.options.errors.container( this.ParsleyInstance.element, this.ParsleyInstance.isRadioOrCheckbox )
@@ -531,6 +563,8 @@
531
563
  }
532
564
 
533
565
  !this.ParsleyInstance.isRadioOrCheckbox ? this.ParsleyInstance.$element.after( ulTemplate ) : this.ParsleyInstance.$element.parent().after( ulTemplate );
566
+
567
+ return this;
534
568
  }
535
569
  };
536
570
 
@@ -585,7 +619,9 @@
585
619
  this.UI = new ParsleyUI( this );
586
620
 
587
621
  // bind some html5 properties
588
- this.bindHtml5Constraints();
622
+ if ( this.options.useHtml5Constraints ) {
623
+ this.bindHtml5Constraints();
624
+ }
589
625
 
590
626
  // bind validators to field
591
627
  this.addConstraints();
@@ -711,7 +747,10 @@
711
747
  this.constraints[ constraint.name ] = $.extend( true, this.constraints[ constraint.name ], constraint );
712
748
 
713
749
  if ( 'string' === typeof message ) {
714
- this.Validator.messages[ constraint.name ] = message ;
750
+ if ( constraint.name === 'type' )
751
+ this.Validator.messages[ constraint.name ][ constraint.requirements ] = message ;
752
+ else
753
+ this.Validator.messages[ constraint.name ] = message ;
715
754
  }
716
755
 
717
756
  // force field validation next check and reset validation events
@@ -863,9 +902,8 @@
863
902
  * @method getLength
864
903
  * @return {int} The length of the value
865
904
  */
866
- , getLength: function(val) {
867
- if (!val || !val.hasOwnProperty('length')) return 0;
868
- return val.length;
905
+ , getLength: function ( val ) {
906
+ return !val || !val.hasOwnProperty( 'length' ) ? 0 : val.length;
869
907
  }
870
908
 
871
909
  /**
@@ -1097,7 +1135,7 @@
1097
1135
  this.$element = $( element );
1098
1136
  this.group = options.group || false;
1099
1137
  this.hash = this.getName();
1100
- this.siblings = this.group ? '[parsley-group="' + this.group + '"]' : 'input[name="' + this.$element.attr( 'name' ) + '"]';
1138
+ this.siblings = this.group ? '[' + options.namespace + 'group="' + this.group + '"]' : 'input[name="' + this.$element.attr( 'name' ) + '"]';
1101
1139
  this.isRadioOrCheckbox = true;
1102
1140
  this.isRadio = this.$element.is( 'input[type=radio]' );
1103
1141
  this.isCheckbox = this.$element.is( 'input[type=checkbox]' );
@@ -1137,7 +1175,7 @@
1137
1175
  throw "A radio / checkbox input must have a parsley-group attribute or a name to be Parsley validated !";
1138
1176
  }
1139
1177
 
1140
- return 'parsley-' + this.$element.attr( 'name' ).replace( /(:|\.|\[|\])/g, '' );
1178
+ return 'parsley-' + this.$element.attr( 'name' ).replace( /(:|\.|\[|\]|\$)/g, '' );
1141
1179
  }
1142
1180
 
1143
1181
  /**
@@ -1246,10 +1284,6 @@
1246
1284
  * @param elem
1247
1285
  */
1248
1286
  , addItem: function ( elem ) {
1249
- if ( $( elem ).is( this.options.excluded ) ) {
1250
- return false;
1251
- }
1252
-
1253
1287
  var ParsleyField = $( elem ).parsley( this.options );
1254
1288
  ParsleyField.setParent( this );
1255
1289
 
@@ -1459,7 +1493,7 @@
1459
1493
  for ( var i in this[ 0 ].attributes ) {
1460
1494
  attribute = this[ 0 ].attributes[ i ];
1461
1495
 
1462
- if ( null !== attribute && attribute.specified && regex.test( attribute.name ) ) {
1496
+ if ( 'undefined' !== typeof attribute && null !== attribute && attribute.specified && regex.test( attribute.name ) ) {
1463
1497
  obj[ camelize( attribute.name.replace( namespace, '' ) ) ] = deserializeValue( attribute.value );
1464
1498
  }
1465
1499
  }
@@ -1530,6 +1564,7 @@
1530
1564
  , errorMessage: false // Customize an unique error message showed if one constraint fails
1531
1565
  , validators: {} // Add your custom validators functions
1532
1566
  , showErrors: true // Set to false if you don't want Parsley to display error messages
1567
+ , useHtml5Constraints: true // Set to false if you don't want Parsley to use html5 constraints
1533
1568
  , messages: {} // Add your own error messages here
1534
1569
 
1535
1570
  //some quite advanced configuration here..
@@ -1541,7 +1576,7 @@
1541
1576
  , errorElem: '<li></li>' // each field constraint fail in an li
1542
1577
  }
1543
1578
  , listeners: {
1544
- onFieldValidate: function ( elem, ParsleyForm ) { return false; } // Executed on validation. Return true to ignore field validation
1579
+ onFieldValidate: function ( elem, ParsleyField ) { return false; } // Executed on validation. Return true to ignore field validation
1545
1580
  , onFormValidate: function ( isFormValid, event, ParsleyForm ) {} // Executed once on form validation. Return (bool) false to block submit, even if valid
1546
1581
  , onFieldError: function ( elem, constraints, ParsleyField ) {} // Executed when a field is detected as invalid
1547
1582
  , onFieldSuccess: function ( elem, constraints, ParsleyField ) {} // Executed when a field passes validation
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsley-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2.0
4
+ version: 1.2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jiri Pospisil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-03 00:00:00.000000000 Z
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -70,6 +70,7 @@ files:
70
70
  - vendor/assets/javascripts/parsley.i18n.ro.js
71
71
  - vendor/assets/javascripts/parsley.i18n.ru.js
72
72
  - vendor/assets/javascripts/parsley.i18n.sv.js
73
+ - vendor/assets/javascripts/parsley.i18n.th.js
73
74
  - vendor/assets/javascripts/parsley.i18n.tr.js
74
75
  - vendor/assets/javascripts/parsley.i18n.ua.js
75
76
  - vendor/assets/javascripts/parsley.i18n.vn.js