Inline display does not allow using altField option
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 |
Thanks for reporting. Feel free to do a pull request.
@samdark sure, but i havent contributed before in any of Yii's repo, are there any guidelines to follow ?
Yes: https://github.com/yiisoft/yii2/blob/master/docs/internals/git-workflow.md
@samdark what i understand is that i have to fork and clone the main Yii2 repo first to contribute the fix to this extension. am i right ? or should i do those 3 steps for the extensions repo directly rather than the Main Yii2 repo first? which i dont think so is the right way.
Sorry to bug you about this.
Yes, you are right. Yii2 repo first.
Any luck with the pull request?
@samdark forgot totally as i was busy lately, just going to push the code can you tell if the CHANGELOG entry will go under 2.0.8 under development section ? i am sure it goes under that.
Merging is blocked as expected since we need to check the pull request first.
@samdark alright, and dont you think a test for the altField with inline display mode should be added too.
Yes, sure it should.