File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
app/code/Magento/Customer Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ public function getLabel()
175
175
public function getFieldHtml ()
176
176
{
177
177
$ this ->dateElement ->setData ([
178
- 'extra_params ' => $ this ->isRequired () ? ' data-validate="{required:true}" ' : '' ,
178
+ 'extra_params ' => $ this ->getHtmlExtraParams () ,
179
179
'name ' => $ this ->getHtmlId (),
180
180
'id ' => $ this ->getHtmlId (),
181
181
'class ' => $ this ->getHtmlClass (),
@@ -201,6 +201,26 @@ public function getHtmlId()
201
201
return 'dob ' ;
202
202
}
203
203
204
+ /**
205
+ * Return data-validate rules
206
+ *
207
+ * @return string
208
+ */
209
+ public function getHtmlExtraParams ()
210
+ {
211
+ $ extraParams = [
212
+ "'validate-date-au':true "
213
+ ];
214
+
215
+ if ($ this ->isRequired ()) {
216
+ $ extraParams [] = 'required:true ' ;
217
+ }
218
+
219
+ $ extraParams = implode (', ' , $ extraParams );
220
+
221
+ return 'data-validate="{ ' . $ extraParams . '}" ' ;
222
+ }
223
+
204
224
/**
205
225
* Returns format which will be applied for DOB in javascript
206
226
*
Original file line number Diff line number Diff line change @@ -464,4 +464,23 @@ public function testGetMaxDateRangeWithException()
464
464
);
465
465
$ this ->assertNull ($ this ->_block ->getMaxDateRange ());
466
466
}
467
+
468
+ public function testGetHtmlExtraParamsWithoutRequiredOption () {
469
+ $ this ->attribute ->expects ($ this ->once ())
470
+ ->method ("isRequired " )
471
+ ->willReturn (false );
472
+
473
+ $ this ->assertEquals ($ this ->_block ->getHtmlExtraParams (), 'data-validate="{ \'validate-date-au \':true}" ' );
474
+ }
475
+
476
+ public function testGetHtmlExtraParamsWithRequiredOption () {
477
+ $ this ->attribute ->expects ($ this ->once ())
478
+ ->method ("isRequired " )
479
+ ->willReturn (true );
480
+
481
+ $ this ->assertEquals (
482
+ $ this ->_block ->getHtmlExtraParams (),
483
+ 'data-validate="{ \'validate-date-au \':true, required:true}" '
484
+ );
485
+ }
467
486
}
You can’t perform that action at this time.
0 commit comments