2amigos / yii2-date-time-picker-widget

Bootstrap DateTimePicker Widget for Yii2
Other
44 stars 36 forks source link

Reset button appearance bug #19

Open igorokb opened 7 years ago

igorokb commented 7 years ago

Hi,

here is a usecase:

DateTimePicker::widget([
        'model' => $searchModel,
        'attribute' => 'sent_at',
        'language' => 'en',
        'size' => 'ms',
        'template' => "{reset}{input}",
        'clientOptions' => [
            'autoclose' => true,
            'minView'=> 'month',
            'format' => 'M d, yyyy',
            'todayBtn' => true
        ]
    ]);

As you can see the template option was adjusted. So basically the calendar button is not needed but the reset button is. Changing of the template this way makes the Reset button disappear, which is obvious following the code from the widget implementation (run() method):

...

     $input = $this->hasModel()
            ? Html::activeTextInput($this->model, $this->attribute, $this->options)
            : Html::textInput($this->name, $this->value, $this->options);

...

       if (strpos($this->template, '{button}') !== false || $this->inline) {
            $input = Html::tag(
                'div',
                strtr($this->template, ['{input}' => $input, '{reset}' => $resetAddon, '{button}' => $pickerAddon]),
                $this->containerOptions
            );
        }
        echo $input;

...

So if there is not {button} in the template, the widget is rendered as single text input

Hope this will help

igorokb commented 7 years ago

Sorry, didn't noticed variable documentation, which states:

the template to render the input. By default, renders as a component, you can render a simple input field without pickup and/or reset buttons by modifying the template to {input}. {button} must exist for a component type of datepicker. The following template is invalid {input}{reset} and will be treated as {input}

But, could you explain why, what is the reason of such restriction?

tonydspaniard commented 7 years ago

Hi @igorokb sorry for the delay. The issue is on these lines: https://github.com/2amigos/yii2-date-time-picker-widget/blob/master/src/DateTimePicker.php#L145

Can you provide a solution? Will be happy to review a PR