name = $name; $this->value = $value; $this->addClass(static::ZBX_STYLE_CLASS); } /** * Set or reset element 'aria-required' attribute to textbox (not the container). * * @param bool $is_required True to set field as required or false if field is not required. * * @return CDateSelector */ public function setAriaRequired($is_required = false) { $this->is_required = $is_required; return $this; } /** * Set date format which calendar will return upon selection. * * @param string $format Date and time format. Usually Y-m-d H:i:s or Y-m-d H:i * * @return CDateSelector */ public function setDateFormat($format) { $this->date_format = $format; return $this; } /** * Add placeholder to date textbox field. * * @param string $text Placeholder text for date textbox field. * * @return CDateSelector */ public function setPlaceholder($text) { $this->placeholder = $text; return $this; } /** * Enable or disable readonly mode for the element. * * @param bool $value * * @return CDateSelector */ public function setReadonly(bool $value): self { $this->readonly = $value; return $this; } /** * Set enabled or disabled state to field. * * @param bool $enabled Field state. * * @return CDateSelector */ public function setEnabled($enabled) { $this->enabled = $enabled; return $this; } /** * Set non-default maxlength attribute to the input field. * * @param int $maxlength * * @return CDateSelector */ public function setMaxLength(int $maxlength) { $this->maxlength = $maxlength; return $this; } /** * Gets string representation of date textbox and calendar button. * * @param bool $destroy * * @return string */ public function toString($destroy = true) { $this ->addItem( (new CTextBox($this->name, $this->value)) ->setId($this->name) ->setAttribute('placeholder', $this->placeholder) ->setAttribute('maxlength', $this->maxlength ?? strlen(date($this->date_format))) ->setAriaRequired($this->is_required) ->setEnabled($this->enabled) ->setReadonly($this->readonly) ) ->addItem((new CButton($this->name.'_calendar')) ->addClass(ZBX_STYLE_BTN_ICON) ->addClass(ZBX_ICON_CALENDAR) ->setEnabled($this->enabled && !$this->readonly) ->onClick('toggleCalendar(this, "'.$this->name.'", "'.$this->date_format.'");')); return parent::toString($destroy); } }