yii2-jui icon indicating copy to clipboard operation
yii2-jui copied to clipboard

Inline display does not allow using altField option

Open buttflattery opened this issue 6 years ago • 10 comments

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

buttflattery avatar Jul 07 '19 02:07 buttflattery

Thanks for reporting. Feel free to do a pull request.

samdark avatar Jul 07 '19 09:07 samdark

@samdark sure, but i havent contributed before in any of Yii's repo, are there any guidelines to follow ?

buttflattery avatar Jul 07 '19 11:07 buttflattery

Yes: https://github.com/yiisoft/yii2/blob/master/docs/internals/git-workflow.md

samdark avatar Jul 07 '19 11:07 samdark

@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.

buttflattery avatar Jul 07 '19 22:07 buttflattery

Yes, you are right. Yii2 repo first.

samdark avatar Jul 07 '19 22:07 samdark

Any luck with the pull request?

samdark avatar Jul 23 '19 16:07 samdark

@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.

buttflattery avatar Jul 24 '19 19:07 buttflattery

Merging is blocked as expected since we need to check the pull request first.

samdark avatar Jul 25 '19 09:07 samdark

@samdark alright, and dont you think a test for the altField with inline display mode should be added too.

buttflattery avatar Jul 25 '19 21:07 buttflattery

Yes, sure it should.

samdark avatar Jul 28 '19 09:07 samdark