Skip to content

Commit

Permalink
Inline mode and side-by-side mode
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
nkovacs committed Mar 28, 2017
1 parent 06e1139 commit ea99923
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions DateTimePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ class DateTimePicker extends \yii\widgets\InputWidget
*/
public $type = self::TYPE_DATETIME;

/**
* @var boolean whether to use inline mode.
*/
public $inline = false;

/**
* @var boolean whether to draw the date and time picker side by side.
*/
public $sideBySide = false;

/**
* @inheritdoc
*/
Expand All @@ -108,23 +118,36 @@ public function init()
public function run()
{
Html::addCssClass($this->options, 'form-control');
$input = $this->hasModel()
? Html::activeTextInput($this->model, $this->attribute, $this->options)
: Html::textInput($this->name, $this->value, $this->options);

$html = '';
$prepend = $this->renderAddon($this->prepend);
$append = $this->renderAddon($this->append);
$addon = false;
if ($prepend !== '' || $append !== '') {
$addon = true;
$html = '';

if ($this->inline) {
$input = $this->hasModel()
? Html::activeHiddenInput($this->model, $this->attribute, $this->options)
: Html::hiddenInput($this->name, $this->value, $this->options);
} else {
$input = $this->hasModel()
? Html::activeTextInput($this->model, $this->attribute, $this->options)
: Html::textInput($this->name, $this->value, $this->options);
$prepend = $this->renderAddon($this->prepend);
$append = $this->renderAddon($this->append);
if ($prepend !== '' || $append !== '') {
$addon = true;
}
}

if ($addon) {
$html .= Html::beginTag('div', ['class' => 'input-group date']);
$html .= $prepend;
} elseif ($this->inline) {
$html .= Html::beginTag('div', ['class' => 'input-group date']);
}
$html .= $input;
if ($addon) {
$html .= $append;
$html .= Html::endTag('div');
} elseif ($this->inline) {
$html .= Html::endTag('div');
}
$this->registerPlugin($addon);
return $html;
Expand Down Expand Up @@ -267,7 +290,14 @@ protected function registerPlugin($addon)
}

if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
$options = $this->clientOptions;
if ($this->inline) {
$options['inline'] = true;
}
if ($this->sideBySide) {
$options['sideBySide'] = true;
}
$options = empty($options) ? '' : Json::htmlEncode($options);
$js = "$selector.datetimepicker($options).find('.clearbutton').on('click', function() {
$selector.data('DateTimePicker').clear();
});";
Expand Down

0 comments on commit ea99923

Please sign in to comment.