Skip to content

Commit

Permalink
active input addon
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Terentev committed Sep 18, 2015
1 parent de97e0b commit d9caf5e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Once the extension is installed, simply use it in your code by :

``phpMomentMapping`` - formats map (Default: ``true``)

``containerOptions`` - widget container options
``containerOptions`` - widget container optionsgit

``clientOptions`` - [full list of available options](http://eonasdan.github.io/bootstrap-datetimepicker/Options/)

Expand Down
56 changes: 44 additions & 12 deletions src/DateTimeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class DateTimeWidget extends InputWidget
* @var array
*/
public $containerOptions = [];
/**
* @var array
*/
public $inputAddonOptions = [];
/**
* @var string
*/
Expand Down Expand Up @@ -92,7 +96,10 @@ public function init()
}
DateTimeAsset::register($this->getView());
$clientOptions = Json::encode($this->clientOptions);
$this->view->registerJs("$('#{$this->options['id']}').datetimepicker({$clientOptions})");
if (!isset($this->containerOptions['id'])) {
$this->containerOptions['id'] = $this->getId();
}
$this->view->registerJs("$('#{$this->containerOptions['id']}').datetimepicker({$clientOptions})");
}

/**
Expand All @@ -106,24 +113,49 @@ public function run()
}
Html::addCssStyle($this->containerOptions, 'position: relative');
$content[] = Html::beginTag('div', $this->containerOptions);
$content[] = $this->renderInput();

if ($this->showInputAddon) {
$content[] = $this->renderInputAddon();
}

$content[] = Html::endTag('div');
return implode("\n", $content);
}

/**
* @return string
*/
protected function renderInput()
{
if ($this->hasModel()) {
$content[] = Html::activeTextInput($this->model, $this->attribute, $this->options);
$content = Html::activeTextInput($this->model, $this->attribute, $this->options);
} else {
$content[] = Html::textInput($this->name, $this->value, $this->options);
$content = Html::textInput($this->name, $this->value, $this->options);
}
return $content;
}

if ($this->showInputAddon) {
$content[] = Html::beginTag('span', ['class' => 'input-group-addon']);
if ($this->inputAddonContent) {
$content[] = $this->inputAddonContent;
} else {
$content[] = Html::tag('span', '', ['class' => 'glyphicon glyphicon-calendar']);
}
$content[] = Html::endTag('span');
/**
* @return string
*/
protected function renderInputAddon()
{
$content = [];
if (!array_key_exists('class', $this->inputAddonOptions)) {
Html::addCssClass($this->inputAddonOptions, 'input-group-addon');
}
if (!array_key_exists('style', $this->inputAddonOptions)) {
Html::addCssStyle($this->inputAddonOptions, ['cursor' => 'pointer']);
}
$content[] = Html::beginTag('span', $this->inputAddonOptions);
if ($this->inputAddonContent) {
$content[] = $this->inputAddonContent;
} else {
$content[] = Html::tag('span', '', ['class' => 'glyphicon glyphicon-calendar']);
}
$content[] = Html::endTag('span');

$content[] = Html::endTag('div');
return implode("\n", $content);
}

Expand Down

0 comments on commit d9caf5e

Please sign in to comment.