/** * Generates control's HTML element. * @return NHtml */ public function getControl() { $selected = $this->getValue(); $selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE); $control = parent::getControl(); $option = NHtml::el('option'); if ($this->prompt !== FALSE) { $control->add($this->prompt instanceof NHtml ? $this->prompt->value('') : (string) $option->value('')->setText($this->translate((string) $this->prompt)) ); } foreach ($this->items as $key => $value) { if (!is_array($value)) { $value = array($key => $value); $dest = $control; } else { $dest = $control->create('optgroup')->label($this->translate($key)); } foreach ($value as $key2 => $value2) { if ($value2 instanceof NHtml) { $dest->add((string) $value2->value($key2) ->selected(isset($selected[$key2]))); } else { $key2 = $this->useKeys ? $key2 : $value2; $dest->add((string) $option->value($key2) ->selected(isset($selected[$key2])) ->setText($this->translate((string) $value2))); } } } return $control; }
/** * Generates control's HTML element. * @param string * @return NHtml */ public function getControl($caption = NULL) { $control = parent::getControl(); $control->value = $this->translate($caption === NULL ? $this->caption : $caption); return $control; }
/** * Generates control's HTML element. * @param mixed key * @return Html */ public function getControl($key = NULL) { if ($key === NULL) { $container = clone $this->container; } elseif (!isset($this->tree[$key])) { return NULL; } $control = parent::getControl(); $name = $control->name; $control->name .= '[]'; $id = $control->id; $label = NHtml::el('label'); $ul = NHtml::el('ul', array('id' => $name)); $container->add(NHtml::el('script', array('type' => "text/javascript"))->add("\$(function(){\$('ul#{$name}').collapsibleCheckboxTree({ checkParents: " . ($this->checkParents ? 'true' : 'false') . ", checkChildren: " . ($this->checkChildren ? 'true' : 'false') . ", uncheckChildren: " . ($this->uncheckChildren ? 'true' : 'false') . ", initialState: '" . $this->initialState . "'});});")); $container->add(NHtml::el('style')->add("#{$name} ul { padding-left:20px;}#{$name} li { list-style:none;}#{$name} ul.hide { display:none;}#{$name} span { color:#999;font-family:'Courier New', Courier, monospace;cursor:default;}#{$name} span.expanded, #{$name} span.collapsed { cursor:pointer;}#{$name} label { float: none; display: inline;}")); foreach ($this->tree->getNodes() as $node) { $ul->add($this->renderNode($node, $control, $label)); } $container->add($ul); return $container; }
function getControl() { $control = parent::getControl(); foreach ($this->getRules() as $rule) { if ($rule->type === NRule::VALIDATOR && !$rule->isNegative && ($rule->operation === NForm::LENGTH || $rule->operation === NForm::MAX_LENGTH)) { $control->maxlength = is_array($rule->arg) ? $rule->arg[1] : $rule->arg; } } if ($this->emptyValue !== '') { $control->data('nette-empty-value', $this->translate($this->emptyValue)); } return $control; }
/** * Generates control's HTML element. * @return NHtml */ public function getControl() { return parent::getControl() ->value($this->forcedValue === NULL ? $this->value : $this->forcedValue) ->data('nette-rules', NULL); }
/** * Generates control's HTML element. * @param mixed * @return NHtml */ public function getControl($key = NULL) { if ($key === NULL) { $container = clone $this->container; $separator = (string) $this->separator; } elseif (!isset($this->items[$key])) { return NULL; } $control = parent::getControl(); $id = $control->id; $counter = -1; $value = $this->value === NULL ? NULL : (string) $this->getValue(); $label = NHtml::el('label'); foreach ($this->items as $k => $val) { $counter++; if ($key !== NULL && (string) $key !== (string) $k) { continue; } $control->id = $label->for = $id . '-' . $counter; $control->checked = (string) $k === $value; $control->value = $k; if ($val instanceof NHtml) { $label->setHtml($val); } else { $label->setText($this->translate((string) $val)); } if ($key !== NULL) { return NHtml::el()->add($control)->add($label); } $container->add((string) $control . (string) $label . $separator); $control->data('nette-rules', NULL); // TODO: separator after last item? } return $container; }
/** * Generates control's HTML element. * @return NHtml */ public function getControl() { return parent::getControl()->checked($this->value); }
/** * Generates control's HTML element. * @return NHtml */ public function getControl() { $control = parent::getControl(); if ($this->prompt) { reset($this->items); $control->data('nette-empty-value', $this->useKeys ? key($this->items) : current($this->items)); } $selected = $this->getValue(); $selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE); $option = NHtml::el('option'); foreach ($this->items as $key => $value) { if (!is_array($value)) { $value = array($key => $value); $dest = $control; } else { $dest = $control->create('optgroup')->label($this->translate($key)); } foreach ($value as $key2 => $value2) { if ($value2 instanceof NHtml) { $dest->add((string) $value2->selected(isset($selected[$key2]))); } else { $key2 = $this->useKeys ? $key2 : $value2; $value2 = $this->translate((string) $value2); $dest->add((string) $option->value($key2 === $value2 ? NULL : $key2) ->selected(isset($selected[$key2])) ->setText($value2)); } } } return $control; }
/** * Generates control's HTML element. * * @param mixed $key Specify a key if you want to render just a single checkbox * @return Nette\Web\Html */ public function getControl($key = NULL) { if ($key === NULL) { $container = clone $this->container; $separator = (string) $this->separator; } elseif (!isset($this->items[$key])) { return NULL; } $control = parent::getControl(); $control->name .= '[]'; $id = $control->id; $counter = -1; $values = $this->value === NULL ? NULL : (array) $this->getValue(); $label = NHtml::el('label'); foreach ($this->items as $k => $val) { $counter++; if ($key !== NULL && $key != $k) { continue; } // intentionally == $control->id = $label->for = $id . '-' . $counter; $control->checked = count($values) > 0 ? in_array($k, $values) : false; $control->value = $k; if ($val instanceof NHtml) { $label->setHtml($val); } else { $label->setText($this->translate($val)); } if ($key !== NULL) { return (string) $control . (string) $label; } $container->add((string) $control . (string) $label . $separator); } return $container; }