@@ -3,7 +3,7 @@ QUnit.module('Validate Element', {
3
3
dataCsv = {
4
4
html_settings : {
5
5
type : 'ActionView::Helpers::FormBuilder' ,
6
- input_tag : '<div class="class_one class_two field_with_errors"><span id="input_tag"></span><label for="user_name" class="message"></label></div>' ,
6
+ input_tag : '<div class="field_with_errors"><span id="input_tag"></span><label for="user_name" class="message"></label></div>' ,
7
7
label_tag : '<div class="field_with_errors"><label id="label_tag"></label></div>'
8
8
} ,
9
9
validators : {
@@ -318,7 +318,7 @@ QUnit.test('Validate when error message needs to change', function (assert) {
318
318
319
319
QUnit . test ( "Don't validate confirmation when not a validatable input" , function ( assert ) {
320
320
dataCsv = {
321
- html_options : {
321
+ html_settings : {
322
322
type : 'ActionView::Helpers::FormBuilder' ,
323
323
input_tag : '<div class="field_with_errors"><span id="input_tag"></span><label for="user_name" class="message"></label></div>' ,
324
324
label_tag : '<div class="field_with_errors"><label id="label_tag"></label></div>'
@@ -327,6 +327,7 @@ QUnit.test("Don't validate confirmation when not a validatable input", function
327
327
}
328
328
329
329
$ ( '#qunit-fixture' )
330
+ . html ( '' )
330
331
. append ( $ ( '<form>' , {
331
332
action : '/users' ,
332
333
'data-client-side-validations' : JSON . stringify ( dataCsv ) ,
@@ -363,10 +364,11 @@ QUnit.test("Don't validate disabled inputs", function (assert) {
363
364
input_tag : '<div class="field_with_errors"><span id="input_tag"></span><label for="user_name" class="message"></label></div>' ,
364
365
label_tag : '<div class="field_with_errors"><label id="label_tag"></label></div>'
365
366
} ,
366
- validators : { 'user_2[name]' : { presence : { message : 'must be present' } } }
367
+ validators : { 'user_2[name]' : { presence : [ { message : 'must be present' } ] } }
367
368
}
368
369
369
370
$ ( '#qunit-fixture' )
371
+ . html ( '' )
370
372
. append ( $ ( '<form>' , {
371
373
action : '/users' ,
372
374
'data-client-side-validations' : JSON . stringify ( dataCsv ) ,
@@ -427,6 +429,47 @@ QUnit.test("Don't validate dynamically disabled inputs", function (assert) {
427
429
assert . notOk ( input . parent ( ) . hasClass ( 'field_with_errors' ) )
428
430
} )
429
431
432
+ QUnit . test ( "Removes error messages when input tag has more than two css classes" , function ( assert ) {
433
+ dataCsv = {
434
+ html_settings : {
435
+ type : 'ActionView::Helpers::FormBuilder' ,
436
+ input_tag : '<div class="class_one class_two field_with_errors"><span id="input_tag"></span><label for="user_name" class="message"></label></div>' ,
437
+ label_tag : '<div class="field_with_errors"><label id="label_tag"></label></div>'
438
+ } ,
439
+ validators : { 'user_2[name]' : { presence : [ { message : 'must be present' } ] } }
440
+ }
441
+
442
+ $ ( '#qunit-fixture' )
443
+ . html ( '' )
444
+ . append ( $ ( '<form>' , {
445
+ action : '/users' ,
446
+ 'data-client-side-validations' : JSON . stringify ( dataCsv ) ,
447
+ method : 'post' ,
448
+ id : 'new_user_2'
449
+ } ) )
450
+ . find ( 'form' )
451
+ . append ( $ ( '<label for="user_2_name">name</label>' ) )
452
+ . append ( $ ( '<input />' , {
453
+ name : 'user_2[name]' ,
454
+ id : 'user_2_name' ,
455
+ type : 'text'
456
+ } ) )
457
+ $ ( 'form#new_user_2' ) . validate ( )
458
+ var form = $ ( 'form#new_user_2' )
459
+ var input = form . find ( 'input#user_2_name' )
460
+
461
+ input . val ( '' )
462
+ input . trigger ( 'focusout' )
463
+
464
+ assert . ok ( input . parent ( ) . hasClass ( 'field_with_errors' ) )
465
+
466
+ input . val ( '123' )
467
+ input . trigger ( 'change' )
468
+ input . trigger ( 'focusout' )
469
+
470
+ assert . notOk ( input . parent ( ) . hasClass ( 'field_with_errors' ) )
471
+ } )
472
+
430
473
QUnit . test ( 'ensure label is scoped to form' , function ( assert ) {
431
474
var form = $ ( 'form#new_user' )
432
475
var input = form . find ( 'input#user_name' )
0 commit comments