Skip to content

New TYPE_HIDDEN #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions DatePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DatePicker extends \kartik\base\InputWidget
const TYPE_COMPONENT_APPEND = 3;
const TYPE_INLINE = 4;
const TYPE_RANGE = 5;
const TYPE_HIDDEN = 6;

/**
* @var string the markup type of widget markup
Expand Down Expand Up @@ -62,6 +63,11 @@ class DatePicker extends \kartik\base\InputWidget
*/
public $addon = '<i class="glyphicon glyphicon-calendar"></i>';

/**
* @var string The element will control the Datepicker for a [[TYPE_HIDDEN]]
*/
public $button = '<button class="btn btn-icon"><i class="glyphicon glyphicon-calendar"></i></button>';

/**
* @var string the model attribute 2 if you are using [[TYPE_RANGE]]
* for markup.
Expand All @@ -73,7 +79,7 @@ class DatePicker extends \kartik\base\InputWidget
* for markup
*/
public $name2;

/**
* @var string the name of value for input number 2 if you are using [[TYPE_RANGE]]
* for markup
Expand Down Expand Up @@ -117,7 +123,7 @@ public function init()
if ($this->type === self::TYPE_RANGE && !class_exists('\\kartik\\field\\FieldRangeAsset')) {
throw new InvalidConfigException("The yii2-field-range extension is not installed and is a pre-requisite for a DatePicker RANGE type. To install this extension run this command on your console: \n\nphp composer.phar require kartik-v/yii2-field-range \"*\"");
}
if ($this->type < 1 || $this->type > 5 || !is_int($this->type)) {
if ($this->type < 1 || $this->type > 6 || !is_int($this->type)) {
throw new InvalidConfigException("Invalid value for the property 'type'. Must be an integer between 1 and 5.");
}
if (isset($this->form) && !($this->form instanceof \yii\widgets\ActiveForm)) {
Expand Down Expand Up @@ -160,7 +166,9 @@ protected function renderInput()
return $this->form->field($this->model, $this->attribute)->widget(self::classname(), $vars);
}

return $this->parseMarkup($this->getInput('textInput'));
$input = $this->type == self::TYPE_HIDDEN ? 'hiddenInput' : 'textInput';

return $this->parseMarkup($this->getInput($input));
}

/**
Expand Down Expand Up @@ -191,6 +199,10 @@ protected function parseMarkup($input)
Html::addCssClass($this->_container, 'date');
return Html::tag('div', "{$input}<span class='input-group-addon'>{$this->addon}</span>", $this->_container);
}
if ($this->type == self::TYPE_HIDDEN) {
Html::addCssClass($this->_container, 'date');
return Html::tag('div', "{$input}{$this->button}", $this->_container);
}
if ($this->type == self::TYPE_RANGE) {
Html::addCssClass($this->_container, 'input-daterange');
if (isset($this->form)) {
Expand Down