yii2-date-time-picker-widget icon indicating copy to clipboard operation
yii2-date-time-picker-widget copied to clipboard

Reset button appearance bug

Open igorokb opened this issue 7 years ago • 2 comments

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 avatar Mar 16 '17 14:03 igorokb

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?

igorokb avatar Mar 16 '17 14:03 igorokb

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

tonydspaniard avatar Jul 05 '17 05:07 tonydspaniard