Skip to content

Commit

Permalink
Fix giving name to widget when it is ActiveField instance
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodeholic committed Jun 19, 2017
1 parent 82f1239 commit 7e65b7a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/DateTimeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class DateTimeWidget extends InputWidget
public function init()
{
parent::init();
if ($this->name !== null){
$this->options['name'] = $this->name;
}
$value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
$this->momentDatetimeFormat = $this->momentDatetimeFormat ?: ArrayHelper::getValue(
$this->getPhpMomentMappings(),
Expand All @@ -101,7 +104,7 @@ public function init()
'class' => 'form-control',
], $this->options);

if ($value !== null && trim($value) !== '') {
if ($value !== null) {
$this->options['value'] = array_key_exists('value', $this->options)
? $this->options['value']
: Yii::$app->formatter->asDatetime($value, $this->phpDatetimeFormat);
Expand Down

0 comments on commit 7e65b7a

Please sign in to comment.