本文整理汇总了PHP中Nette\Forms\Form::getElementPrototype方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getElementPrototype方法的具体用法?PHP Form::getElementPrototype怎么用?PHP Form::getElementPrototype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Form
的用法示例。
在下文中一共展示了Form::getElementPrototype方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderFormEnd
/**
* Renders form end.
*
* @return string
*/
public static function renderFormEnd(Form $form)
{
$s = '';
if (strcasecmp($form->getMethod(), 'get') === 0) {
$url = explode('?', $form->getElementPrototype()->action, 2);
if (isset($url[1])) {
foreach (preg_split('#[;&]#', $url[1]) as $param) {
$parts = explode('=', $param, 2);
$name = urldecode($parts[0]);
if (!isset($form[$name])) {
$s .= Nette\Utils\Html::el('input', array('type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])));
}
}
}
}
foreach ($form->getComponents(true, 'Nette\\Forms\\Controls\\HiddenField') as $control) {
if (!$control->getOption('rendered')) {
$s .= $control->getControl();
}
}
if (iterator_count($form->getComponents(true, 'Nette\\Forms\\Controls\\TextInput')) < 2) {
$s .= '<!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->';
}
echo ($s ? "<div>{$s}</div>\n" : '') . $form->getElementPrototype()->endTag() . "\n";
}
示例2: decorateFormControls
private function decorateFormControls()
{
$this->form->getElementPrototype()->class('form-horizontal');
$this->usedPrimary = FALSE;
foreach ($this->form->getControls() as $control) {
if ($control instanceof NetteBaseControl) {
$this->decorateFormControl($control);
}
}
}
示例3: render
/**
* Render the templates
*
* @param \Nette\Forms\Form $form
* @param string $mode
*
* @return void
*/
public function render(Nette\Forms\Form $form, $mode = NULL)
{
if ($this->form !== $form) {
$this->form = $form;
// translators
if ($translator = $this->form->getTranslator()) {
$this->template->setTranslator($translator);
}
// controls placeholders & classes
foreach ($this->form->getControls() as $control) {
$this->prepareControl($control);
}
$formEl = $form->getElementPrototype();
if (!$formEl->class || stripos('form-', (string) $formEl->class) === FALSE) {
$formEl->addClass('form-horizontal');
}
}
$this->template->form = $this->form;
$this->template->_form = $this->form;
$this->template->renderer = $this;
if ($mode === NULL) {
$this->template->render();
} elseif ($mode === 'begin') {
FormMacros::renderFormBegin($this->form, array());
} elseif ($mode === 'end') {
FormMacros::renderFormEnd($this->form);
} else {
$this->template->setFile(__DIR__ . '/@parts.latte');
$this->template->mode = $mode;
$this->template->render();
$this->template->setFile(__DIR__ . '/@form.latte');
}
}
示例4: getToggleScript
private function getToggleScript(Rules $rules, $cond = NULL)
{
$s = '';
foreach ($rules->getToggles() as $id => $visible) {
$s .= "visible = true; {$cond}\n" . "nette.toggle(" . Nette\Json::encode((string) $id) . ", " . ($visible ? '' : '!') . "visible);\n";
}
$formName = Nette\Json::encode((string) $this->form->getElementPrototype()->id);
foreach ($rules as $rule) {
if ($rule->type === Rule::CONDITION && is_string($rule->operation)) {
$script = $this->getClientScript($rule->control, $rule->operation, $rule->arg);
if ($script) {
$res = $this->getToggleScript($rule->subRules, $cond . "{$script} visible = visible && " . ($rule->isNegative ? '!' : '') . "res;\n");
if ($res) {
$el = $rule->control->getControlPrototype();
if ($el->getName() === 'select') {
$el->onchange("nette.forms[{$formName}].toggle(this)", TRUE);
} else {
$el->onclick("nette.forms[{$formName}].toggle(this)", TRUE);
//$el->onkeyup("nette.forms[$formName].toggle(this)", TRUE);
}
$s .= $res;
}
}
}
}
return $s;
}
示例5: render
/**
* Render the templates.
* @param Form $form
* @param string $mode
* @param array $args
*/
public function render(Form $form, $mode = NULL, $args = NULL)
{
if ($this->template === NULL) {
if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
/** @var \Nette\Application\UI\Presenter $presenter */
$this->template = clone $presenter->getTemplate();
} else {
$this->template = new FileTemplate();
$this->template->registerFilter(new \Nette\Latte\Engine());
}
}
if ($this->form !== $form) {
$this->form = $form;
// translators
if ($translator = $this->form->getTranslator()) {
$this->template->setTranslator($translator);
}
// controls placeholders & classes
foreach ($this->form->getControls() as $control) {
$this->prepareControl($control);
}
$formEl = $form->getElementPrototype();
if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
//$formEl->addClass('form-horizontal');
}
} elseif ($mode === 'begin') {
foreach ($this->form->getControls() as $control) {
/** @var \Nette\Forms\Controls\BaseControl $control */
$control->setOption('rendered', FALSE);
}
}
$this->template->setFile(__DIR__ . '/@form.latte');
$this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
if ($mode === NULL) {
if ($args) {
$this->form->getElementPrototype()->addAttributes($args);
}
$this->template->render();
} elseif ($mode === 'begin') {
FormMacros::renderFormBegin($this->form, (array) $args);
} elseif ($mode === 'end') {
FormMacros::renderFormEnd($this->form);
} else {
$attrs = array('input' => array(), 'label' => array());
foreach ((array) $args as $key => $val) {
if (stripos($key, 'input-') === 0) {
$attrs['input'][substr($key, 6)] = $val;
} elseif (stripos($key, 'label-') === 0) {
$attrs['label'][substr($key, 6)] = $val;
}
}
$this->template->setFile(__DIR__ . '/@parts.latte');
$this->template->mode = $mode;
$this->template->attrs = (array) $attrs;
$this->template->render();
}
}
示例6: render
/**
* @param Nette\Forms\Form $form
* @param null $mode
*
* @return mixed
*/
public function render(Nette\Forms\Form $form, $mode = null)
{
$form->getElementPrototype()->addClass('form-horizontal');
$form->getElementPrototype()->setNovalidate('novalidate');
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
if (strpos($control->getControlPrototype()->getClass(), 'btn') === FALSE) {
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
$usedPrimary = true;
}
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
return parent::render($form, $mode);
}
示例7: renderEnd
/**
* Renders form end.
* @return string
*/
public function renderEnd()
{
$s = '';
foreach ($this->form->getControls() as $control) {
if ($control instanceof HiddenField && !$control->getOption('rendered')) {
$s .= (string) $control->getControl();
}
}
if ($s) {
$s = $this->getWrapper('hidden container')->setHtml($s) . "\n";
}
return $s . $this->form->getElementPrototype()->endTag() . "\n";
}
示例8: renderFormEnd
/**
* Renders form end.
* @return string
*/
public static function renderFormEnd(Form $form, $withTags = TRUE)
{
$s = '';
if (strcasecmp($form->getMethod(), 'get') === 0) {
foreach (preg_split('#[;&]#', parse_url($form->getElementPrototype()->action, PHP_URL_QUERY), NULL, PREG_SPLIT_NO_EMPTY) as $param) {
$parts = explode('=', $param, 2);
$name = urldecode($parts[0]);
if (!isset($form[$name])) {
$s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]);
}
}
}
foreach ($form->getControls() as $control) {
if ($control->getOption('type') === 'hidden' && !$control->getOption('rendered')) {
$s .= $control->getControl();
}
}
if (iterator_count($form->getComponents(TRUE, Nette\Forms\Controls\TextInput::class)) < 2) {
$s .= "<!--[if IE]><input type=IEbug disabled style=\"display:none\"><![endif]-->\n";
}
return $s . ($withTags ? $form->getElementPrototype()->endTag() . "\n" : '');
}
示例9: renderEnd
/**
* Renders form end.
* @return string
*/
public function renderEnd()
{
$s = '';
foreach ($this->form->getControls() as $control) {
if ($control instanceof Nette\Forms\Controls\HiddenField && !$control->getOption('rendered')) {
$s .= (string) $control->getControl();
}
}
if (iterator_count($this->form->getComponents(TRUE, 'Nette\\Forms\\Controls\\TextInput')) < 2) {
$s .= '<!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->';
}
if ($s) {
$s = $this->getWrapper('hidden container')->setHtml($s) . "\n";
}
return $s . $this->form->getElementPrototype()->endTag() . "\n";
}
示例10: render
public function render(\Nette\Forms\Form $form, $mode = null)
{
$this->wrappers['controls']['container'] = 'div class=col-sm-12';
$this->wrappers['pair']['container'] = 'div class=form-group';
$this->wrappers['control']['container'] = 'div class=col-lg-8';
$this->wrappers['label']['container'] = 'label class=col-lg-4';
// make form and controls compatible with Twitter Bootstrap
$form->getElementPrototype()->class('form-horizontal');
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
$usedPrimary = true;
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
return parent::render($form, $mode);
}
示例11: render
/**
* Render the templates
*
* @param \Nette\Forms\Form $form
*
* @return void
*/
public function render(Nette\Forms\Form $form)
{
if ($this->form !== $form) {
$this->form = $form;
// translators
if ($translator = $this->form->getTranslator()) {
$this->template->setTranslator($translator);
}
// controls placeholders & classes
foreach ($this->form->getControls() as $control) {
$this->prepareControl($control);
}
$formEl = $form->getElementPrototype();
if (stripos('form-', $formEl->class) === FALSE) {
$formEl->addClass('form-horizontal');
}
}
$this->template->form = $this->form;
$this->template->renderer = $this;
$this->template->render();
}
示例12: prepareForm
/**
* Make form and controls compatible with Twitter Bootstrap
* @param Form $form
*/
protected function prepareForm(Form $form)
{
$form->getElementPrototype()->class[] = 'form-horizontal';
$translator = $form->getTranslator();
foreach ($form->controls as $control) {
/** @var BaseControl $control */
if ($control instanceof HiddenField) {
continue;
} elseif ($control instanceof Button) {
$control->controlPrototype->class[] = "btn-block btn-lg";
} else {
if ($control->getLabel()) {
$control->setAttribute('placeholder', $control->caption);
if (empty($control->controlPrototype->attrs['title'])) {
$control->setAttribute('title', $translator ? $translator->translate($control->caption) : $control->caption);
}
$control->getLabelPrototype()->attrs["style"] = "display:none";
}
}
}
BootstrapHelper::ApplyBootstrapToControls($form);
}
示例13: bootstrapForm
public static function bootstrapForm(Form $form)
{
// setup form rendering
$renderer = $form->getRenderer();
$renderer->wrappers['controls']['container'] = NULL;
$renderer->wrappers['pair']['container'] = 'div class="form-group"';
$renderer->wrappers['pair']['.error'] = 'has-error';
$renderer->wrappers['control']['container'] = 'div class="col-sm-9"';
$renderer->wrappers['label']['container'] = 'div class="col-sm-3 control-label"';
$renderer->wrappers['control']['description'] = 'span class=help-block';
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
// make form and controls compatible with Twitter Bootstrap
$form->getElementPrototype()->class('form-horizontal');
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-shadow' : 'btn btn-default');
$usedPrimary = TRUE;
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control form-control-shadow');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
}
示例14: addFormModeClass
private function addFormModeClass(Form $form, array &$attrs)
{
if ($this->renderMode !== RenderModeEnum::VERTICAL) {
if (isset($attrs['class'])) {
$classes = explode(' ', $attrs['class']);
$pos = array_search('no-' . $this->renderMode, $classes, TRUE);
if ($pos !== FALSE) {
// if .no-form-<mode> class is present, remove it and not include form-<mode> class
unset($classes[$pos]);
} else {
// otherwise add form-<mode> class
$classes[] = $this->renderMode;
}
if (count($classes) === 0) {
unset($attrs['class']);
} else {
$attrs['class'] = implode(' ', $classes);
}
} else {
$classes = $form->getElementPrototype()->getAttribute('class');
if (is_string($classes)) {
$classes = explode(' ', $classes);
} elseif (!is_array($classes)) {
$classes = [];
}
$classes[] = $this->renderMode;
$attrs['class'] = implode(' ', $classes);
}
}
}
示例15: prepareForm
/**
* Make form and controls compatible with Twitter Bootstrap
* @param Form $form
*/
protected function prepareForm(Form $form)
{
$form->getElementPrototype()->class[] = 'form-inline';
BootstrapHelper::ApplyBootstrapToControls($form);
}