Skip to content

Commit 787a46b

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-48535' into BUGS
2 parents ea764d0 + 95419e5 commit 787a46b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function getLabel()
175175
public function getFieldHtml()
176176
{
177177
$this->dateElement->setData([
178-
'extra_params' => $this->isRequired() ? 'data-validate="{required:true}"' : '',
178+
'extra_params' => $this->getHtmlExtraParams(),
179179
'name' => $this->getHtmlId(),
180180
'id' => $this->getHtmlId(),
181181
'class' => $this->getHtmlClass(),
@@ -201,6 +201,26 @@ public function getHtmlId()
201201
return 'dob';
202202
}
203203

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+
204224
/**
205225
* Returns format which will be applied for DOB in javascript
206226
*

app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,4 +464,23 @@ public function testGetMaxDateRangeWithException()
464464
);
465465
$this->assertNull($this->_block->getMaxDateRange());
466466
}
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+
}
467486
}

0 commit comments

Comments
 (0)