@@ -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,47 @@ QUnit.module('Validate Element', {
132135 id : 'customized_field' ,
133136 type : 'text'
134137 } ) )
135-
138+ . append ( $ ( `
139+ <label for="user_date_of_sign_up">Date field</label>
140+ <input name="user[date_of_sign_up]"
141+ id="user_date_of_sign_up"
142+ type="date">
143+ ` ) )
144+ . append ( $ ( `
145+ <label for="user_time_of_birth_1i">Time select</label>
146+ <input type="hidden" id="user_time_of_birth_1i" name="user[time_of_birth(1i)]" value="1">
147+ <input type="hidden" id="user_time_of_birth_2i" name="user[time_of_birth(2i)]" value="1">
148+ <input type="hidden" id="user_time_of_birth_3i" name="user[time_of_birth(3i)]" value="1">
149+ <select id="user_time_of_birth_4i" name="user[time_of_birth(4i)]" >
150+ <option value=""></option>
151+ <option value="00">00</option>
152+ <option value="01">01</option>
153+ </select>
154+ :
155+ <select id="user_time_of_birth_5i" name="user[time_of_birth(5i)]" >
156+ <option value=""></option>
157+ <option value="00">00</option>
158+ <option value="01">59</option>
159+ </select>
160+ ` ) )
161+ . append ( $ ( `
162+ <label for="user_date_of_birth_1i">Date select</label>
163+ <select id="user_date_of_birth_1i" name="user[date_of_birth(1i)]">
164+ <option value=""></option>
165+ <option value="2015">2015</option>
166+ <option value="2016">2016</option>
167+ </select>
168+ <select id="user_date_of_birth_2i" name="user[date_of_birth(2i)]">
169+ <option value=""></option>
170+ <option value="1">January</option>
171+ <option value="2">February</option>
172+ </select>
173+ <select id="user_date_of_birth_3i" name="user[date_of_birth(3i)]">
174+ <option value=""></option>
175+ <option value="1">1</option>
176+ <option value="2">2</option>
177+ </select>
178+ ` ) )
136179 $ ( 'form#new_user' ) . validate ( )
137180 } ,
138181
@@ -152,6 +195,58 @@ QUnit.test('Validate when focusouting on customized_field', function (assert) {
152195 assert . ok ( label . parent ( ) . hasClass ( 'field_with_errors' ) )
153196} )
154197
198+ QUnit . test ( 'Validate when focusouting on date_field' , function ( assert ) {
199+ let form = $ ( 'form#new_user' )
200+ let input = form . find ( 'input#user_date_of_sign_up' )
201+ let label = $ ( 'label[for="user_date_of_sign_up"]' )
202+
203+ input . trigger ( 'focusout' )
204+ assert . ok ( input . parent ( ) . hasClass ( 'field_with_errors' ) )
205+ assert . ok ( label . parent ( ) . hasClass ( 'field_with_errors' ) )
206+ } )
207+
208+ QUnit . test ( 'Validate validations of date_select' , function ( assert ) {
209+ let form = $ ( 'form#new_user' )
210+
211+ //let label = $('label[for="user_date_of_birth_1i"]')
212+ let input_year = form . find ( 'select#user_date_of_birth_1i' )
213+ let input_month = form . find ( 'select#user_date_of_birth_2i' )
214+ let input_day = form . find ( 'select#user_date_of_birth_3i' )
215+
216+ input_year . trigger ( 'focusout' )
217+ assert . ok ( input_year . parent ( ) . hasClass ( 'field_with_errors' ) )
218+
219+ input_month . trigger ( 'focusout' )
220+ assert . ok ( input_month . parent ( ) . hasClass ( 'field_with_errors' ) )
221+
222+ input_day . trigger ( 'focusout' )
223+ assert . ok ( input_day . parent ( ) . hasClass ( 'field_with_errors' ) )
224+
225+ // showing validation messages doesnt work well with this.
226+ // JS Formbuilder must be customized for these types of fields
227+ // to share error message and hide error only when all 3 selects are valid
228+
229+ } )
230+
231+ QUnit . test ( 'Validate validations of time_select' , function ( assert ) {
232+ let form = $ ( 'form#new_user' )
233+
234+ //let label = $('label[for="user_time_of_birth_4i"]')
235+ let input_hour = form . find ( 'select#user_time_of_birth_4i' )
236+ let input_minute = form . find ( 'select#user_time_of_birth_5i' )
237+
238+ input_hour . trigger ( 'focusout' )
239+ assert . ok ( input_hour . parent ( ) . hasClass ( 'field_with_errors' ) )
240+
241+ input_minute . trigger ( 'focusout' )
242+ assert . ok ( input_minute . parent ( ) . hasClass ( 'field_with_errors' ) )
243+
244+ // showing validation messages doesnt work well with this.
245+ // JS Formbuilder must be customized for these types of fields
246+ // to share error message and hide error only when all 3 selects are valid
247+ } )
248+
249+
155250QUnit . test ( 'Validate when focusouting' , function ( assert ) {
156251 var form = $ ( 'form#new_user' )
157252 var input = form . find ( 'input#user_name' )
0 commit comments