Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Reset button appearance bug #19

Open
igorokb opened this issue Mar 16, 2017 · 2 comments
Open

Reset button appearance bug #19

igorokb opened this issue Mar 16, 2017 · 2 comments

Comments

@igorokb
Copy link

igorokb commented Mar 16, 2017

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
Copy link
Author

igorokb commented Mar 16, 2017

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
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants