Skip to content

Inline display does not allow using altField option #87

@buttflattery

Description

@buttflattery

What steps will reproduce the problem?

Create a datepicker with the following options where you use inline option along with the altField option

echo DatePicker::widget([
    'name' => 'date_range',
    'inline' => true,
    'clientOptions' => [
        'selectOtherMonths' => true,
        'altField' => '#shootssearch-created_at',
    ]
]);

and create an active field using yii\helpers\Html or ActiveForm to be used as an actual form field to be submitted along with the datepicker value when form is submitted.

echo Html::activeTextInput($model, 'created_at');

What's expected?

i expect the field to be populated with the date value selected from the datepicker

What do you get instead?

nothing happens and the field stays blank

The reason behind is that for inline display you have the following code on line 201 in renderWidget() function

$this->clientOptions['altField'] = '#' . $this->options['id'];

which overrides the custom defined altField .

you can change that line to something like below which will work for both cases

  • default hidden field created by the widget.
  • the custom field if the user defines one using the altField .
$customAltField = yii\helprs\ArrayHelper::getValue($this->clientOptions, 'altField', false);
$this->clientOptions['altField'] = '#' . $this->options['id'];
if ($customAltField) {
    $this->clientOptions['altField'] .=  ', ' . $customAltField;
}

Additional info

Q A
Yii vesion 2.0.20
PHP version 5.6
Operating system Windows 10

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions