@@ -18,7 +18,10 @@ QUnit.module('Validate Element', {
1818 'user[phone_numbers_attributes][deeply][nested][][attribute]' : { presence : [ { message : 'must be present' } ] } ,
1919 'user[phone_numbers_attributes][][labels_attributes][][label]' : { presence : [ { message : 'must be present' } ] } ,
2020 'user[a_attributes][][b_attributes][][c_attributes][][d_attributes][][e]' : { presence : [ { message : 'must be present' } ] } ,
21- customized_field : { length : [ { messages : { minimum : 'is too short (minimum is 4 characters)' } , minimum : 4 } ] }
21+ customized_field : { length : [ { messages : { minimum : 'is too short (minimum is 4 characters)' } , minimum : 4 } ] } ,
22+ 'user[date_of_sign_up]' : { presence : [ { message : 'must be present' } ] } ,
23+ 'user[date_of_birth]' : { presence : [ { message : 'must be present' } ] } ,
24+ 'user[time_of_birth]' : { presence : [ { message : 'must be present' } ] } ,
2225 }
2326 }
2427
@@ -132,7 +135,73 @@ QUnit.module('Validate Element', {
132135 id : 'customized_field' ,
133136 type : 'text'
134137 } ) )
135-
138+ . append ( $ ( '<label for="user_date_of_sign_up">Date Field</label>' ) )
139+ . append ( $ ( '<input />' , {
140+ name : 'user[date_of_sign_up]' ,
141+ id : 'user_date_of_sign_up' ,
142+ type : 'date'
143+ } ) )
144+ . append ( $ ( '<label for="user_time_of_birth_1i">Time select</label>' ) )
145+ . append ( $ ( '<input />' , {
146+ type : 'hidden' ,
147+ id : 'user_time_of_birth_1i' ,
148+ name : 'user[time_of_birth(1i)]' ,
149+ value : 1
150+ } ) )
151+ . append ( $ ( '<input />' , {
152+ type : 'hidden' ,
153+ id : 'user_time_of_birth_2i' ,
154+ name : 'user[time_of_birth(2i)]' ,
155+ value : 1
156+ } ) )
157+ . append ( $ ( '<input />' , {
158+ type : 'hidden' ,
159+ id : 'user_time_of_birth_3i' ,
160+ name : 'user[time_of_birth(3i)]' ,
161+ value : 1
162+ } ) )
163+ . append ( $ ( '<select>' , {
164+ id : 'user_time_of_birth_4i' ,
165+ name : 'user[time_of_birth(4i)]' ,
166+ } )
167+ . append ( $ ( '<option value=""></option>' ) )
168+ . append ( $ ( '<option value="00">00</option>' ) )
169+ . append ( $ ( '<option value="01">01</option>' ) )
170+ )
171+ . append ( ':' )
172+ . append ( $ ( '<select>' , {
173+ id : 'user_time_of_birth_5i' ,
174+ name : 'user[time_of_birth(5i)]' ,
175+ } )
176+ . append ( $ ( '<option value=""></option>' ) )
177+ . append ( $ ( '<option value="00">00</option>' ) )
178+ . append ( $ ( '<option value="59">59</option>' ) )
179+ )
180+ . append ( $ ( '<label for="user_date_of_birth_1i">Date select</label>' ) )
181+ . append ( $ ( '<select>' , {
182+ id : 'user_date_of_birth_1i' ,
183+ name : 'user[time_of_birth(1i)]' ,
184+ } )
185+ . append ( $ ( '<option value=""></option>' ) )
186+ . append ( $ ( '<option value="2015">2015</option>' ) )
187+ . append ( $ ( '<option value="2016">2016</option>' ) )
188+ )
189+ . append ( $ ( '<select>' , {
190+ id : 'user_date_of_birth_2i' ,
191+ name : 'user[time_of_birth(2i)]' ,
192+ } )
193+ . append ( $ ( '<option value=""></option>' ) )
194+ . append ( $ ( '<option value="1">January</option>' ) )
195+ . append ( $ ( '<option value="2">February</option>' ) )
196+ )
197+ . append ( $ ( '<select>' , {
198+ id : 'user_date_of_birth_3i' ,
199+ name : 'user[time_of_birth(3i)]' ,
200+ } )
201+ . append ( $ ( '<option value=""></option>' ) )
202+ . append ( $ ( '<option value="1">2</option>' ) )
203+ . append ( $ ( '<option value="2">2</option>' ) )
204+ )
136205 $ ( 'form#new_user' ) . validate ( )
137206 } ,
138207
@@ -152,6 +221,58 @@ QUnit.test('Validate when focusouting on customized_field', function (assert) {
152221 assert . ok ( label . parent ( ) . hasClass ( 'field_with_errors' ) )
153222} )
154223
224+ QUnit . test ( 'Validate when focusouting on date_field' , function ( assert ) {
225+ var form = $ ( 'form#new_user' )
226+ var input = form . find ( 'input#user_date_of_sign_up' )
227+ var label = $ ( 'label[for="user_date_of_sign_up"]' )
228+
229+ input . trigger ( 'focusout' )
230+ assert . ok ( input . parent ( ) . hasClass ( 'field_with_errors' ) )
231+ assert . ok ( label . parent ( ) . hasClass ( 'field_with_errors' ) )
232+ } )
233+
234+ QUnit . test ( 'Validate validations of date_select' , function ( assert ) {
235+ var form = $ ( 'form#new_user' )
236+
237+ //var label = $('label[for="user_date_of_birth_1i"]')
238+ var input_year = form . find ( 'select#user_date_of_birth_1i' )
239+ var input_month = form . find ( 'select#user_date_of_birth_2i' )
240+ var input_day = form . find ( 'select#user_date_of_birth_3i' )
241+
242+ input_year . trigger ( 'focusout' )
243+ assert . ok ( input_year . parent ( ) . hasClass ( 'field_with_errors' ) )
244+
245+ input_month . trigger ( 'focusout' )
246+ assert . ok ( input_month . parent ( ) . hasClass ( 'field_with_errors' ) )
247+
248+ input_day . trigger ( 'focusout' )
249+ assert . ok ( input_day . parent ( ) . hasClass ( 'field_with_errors' ) )
250+
251+ // showing validation messages doesnt work well with this.
252+ // JS Formbuilder must be customized for these types of fields
253+ // to share error message and hide error only when all 3 selects are valid
254+
255+ } )
256+
257+ QUnit . test ( 'Validate validations of time_select' , function ( assert ) {
258+ var form = $ ( 'form#new_user' )
259+
260+ //var label = $('label[for="user_time_of_birth_4i"]')
261+ var input_hour = form . find ( 'select#user_time_of_birth_4i' )
262+ var input_minute = form . find ( 'select#user_time_of_birth_5i' )
263+
264+ input_hour . trigger ( 'focusout' )
265+ assert . ok ( input_hour . parent ( ) . hasClass ( 'field_with_errors' ) )
266+
267+ input_minute . trigger ( 'focusout' )
268+ assert . ok ( input_minute . parent ( ) . hasClass ( 'field_with_errors' ) )
269+
270+ // showing validation messages doesnt work well with this.
271+ // JS Formbuilder must be customized for these types of fields
272+ // to share error message and hide error only when all 3 selects are valid
273+ } )
274+
275+
155276QUnit . test ( 'Validate when focusouting' , function ( assert ) {
156277 var form = $ ( 'form#new_user' )
157278 var input = form . find ( 'input#user_name' )
0 commit comments