Skip to content

Commit

Permalink
Merge pull request #14 from lulco/patch-1
Browse files Browse the repository at this point in the history
Updated version of nette/forms
  • Loading branch information
tomaj authored Mar 29, 2019
2 parents c9ec7f2 + 906ea20 commit 174f04d
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 111 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
}
],
"require": {
"php": ">= 5.3.7",
"nette/forms": "~2.3"
"php": ">= 7.1.0",
"nette/forms": "^3.0"
},
"autoload": {
"classmap": [
Expand Down
72 changes: 36 additions & 36 deletions src/BootstrapInlineRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@

namespace Tomaj\Form\Renderer;

use Nette;
use Nette\Forms\Controls\Button;
use Nette\Forms\Controls\Checkbox;
use Nette\Forms\Controls\CheckboxList;
use Nette\Forms\Controls\MultiSelectBox;
use Nette\Forms\Controls\RadioList;
use Nette\Forms\Controls\SelectBox;
use Nette\Forms\Controls\TextBase;
use Nette\Forms\Form;
use Nette\Forms\Rendering\DefaultFormRenderer;
use Nette\Forms\Controls;

class BootstrapInlineRenderer extends DefaultFormRenderer
{
public $wrappers = array(
'form' => array(
public $wrappers = [
'form' => [
'container' => '',
),
'error' => array(
],
'error' => [
'container' => 'div class="alert alert-danger"',
'item' => 'p',
),
'group' => array(
],
'group' => [
'container' => 'fieldset',
'label' => 'legend',
'description' => 'p',
),
'controls' => array(
],
'controls' => [
'container' => '',
),
'pair' => array(
],
'pair' => [
'container' => 'div class=form-group',
'.required' => 'required',
'.optional' => null,
'.odd' => null,
'.error' => 'has-error',
),
'control' => array(
],
'control' => [
'container' => null,
'.odd' => null,
'description' => 'span class=help-block',
Expand All @@ -45,32 +51,26 @@ class BootstrapInlineRenderer extends DefaultFormRenderer
'.submit' => 'button',
'.image' => 'imagebutton',
'.button' => 'button',
),
'label' => array(
],
'label' => [
'container' => '',
'suffix' => null,
'requiredsuffix' => '',
),
'hidden' => array(
],
'hidden' => [
'container' => 'div',
),
);
],
];

/** @var bool */
private $novalidate;

public function __construct($novalidate = true)
public function __construct(bool $novalidate = true)
{
$this->novalidate = $novalidate;
}

/**
* Provides complete form rendering.
* @param Nette\Forms\Form
* @param string 'begin', 'errors', 'ownerrors', 'body', 'end' or empty to render all
* @return string
*/
public function render(Nette\Forms\Form $form, $mode = null)
public function render(Form $form, string $mode = null): string
{
$form->getElementPrototype()->addClass('form-inline');

Expand All @@ -79,18 +79,18 @@ public function render(Nette\Forms\Form $form, $mode = null)
}

foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
if (strpos($control->getControlPrototype()->getClass(), 'btn') === FALSE) {
if ($control instanceof 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) {
} elseif ($control instanceof TextBase ||
$control instanceof SelectBox ||
$control instanceof MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox ||
$control instanceof Controls\CheckboxList ||
$control instanceof Controls\RadioList) {
} elseif ($control instanceof Checkbox ||
$control instanceof CheckboxList ||
$control instanceof RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
Expand Down
72 changes: 36 additions & 36 deletions src/BootstrapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@

namespace Tomaj\Form\Renderer;

use Nette;
use Nette\Forms\Controls\Button;
use Nette\Forms\Controls\Checkbox;
use Nette\Forms\Controls\CheckboxList;
use Nette\Forms\Controls\MultiSelectBox;
use Nette\Forms\Controls\RadioList;
use Nette\Forms\Controls\SelectBox;
use Nette\Forms\Controls\TextBase;
use Nette\Forms\Form;
use Nette\Forms\Rendering\DefaultFormRenderer;
use Nette\Forms\Controls;

class BootstrapRenderer extends DefaultFormRenderer
{
public $wrappers = array(
'form' => array(
public $wrappers = [
'form' => [
'container' => null,
),
'error' => array(
],
'error' => [
'container' => 'div class="alert alert-danger"',
'item' => 'p',
),
'group' => array(
],
'group' => [
'container' => 'fieldset',
'label' => 'legend',
'description' => 'p',
),
'controls' => array(
],
'controls' => [
'container' => 'div',
),
'pair' => array(
],
'pair' => [
'container' => 'div class=form-group',
'.required' => 'required',
'.optional' => null,
'.odd' => null,
'.error' => 'has-error',
),
'control' => array(
],
'control' => [
'container' => 'div class=col-sm-9',
'.odd' => null,
'description' => 'span class=help-block',
Expand All @@ -45,32 +51,26 @@ class BootstrapRenderer extends DefaultFormRenderer
'.submit' => 'button',
'.image' => 'imagebutton',
'.button' => 'button',
),
'label' => array(
],
'label' => [
'container' => 'div class="col-sm-3 control-label"',
'suffix' => null,
'requiredsuffix' => '',
),
'hidden' => array(
],
'hidden' => [
'container' => 'div',
),
);
],
];

/** @var bool */
private $novalidate;

public function __construct($novalidate = true)
public function __construct(bool $novalidate = true)
{
$this->novalidate = $novalidate;
}

/**
* Provides complete form rendering.
* @param Nette\Forms\Form
* @param string 'begin', 'errors', 'ownerrors', 'body', 'end' or empty to render all
* @return string
*/
public function render(Nette\Forms\Form $form, $mode = null)
public function render(Form $form, string $mode = null): string
{
$form->getElementPrototype()->addClass('form-horizontal');

Expand All @@ -79,18 +79,18 @@ public function render(Nette\Forms\Form $form, $mode = null)
}

foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
if (strpos($control->getControlPrototype()->getClass(), 'btn') === FALSE) {
if ($control instanceof 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) {
} elseif ($control instanceof TextBase ||
$control instanceof SelectBox ||
$control instanceof MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox ||
$control instanceof Controls\CheckboxList ||
$control instanceof Controls\RadioList) {
} elseif ($control instanceof Checkbox ||
$control instanceof CheckboxList ||
$control instanceof RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
Expand Down
74 changes: 37 additions & 37 deletions src/BootstrapVerticalRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@

namespace Tomaj\Form\Renderer;

use Nette;
use Nette\Forms\Controls\Button;
use Nette\Forms\Controls\Checkbox;
use Nette\Forms\Controls\CheckboxList;
use Nette\Forms\Controls\MultiSelectBox;
use Nette\Forms\Controls\RadioList;
use Nette\Forms\Controls\SelectBox;
use Nette\Forms\Controls\TextBase;
use Nette\Forms\Form;
use Nette\Forms\Rendering\DefaultFormRenderer;
use Nette\Forms\Controls;

class BootstrapVerticalRenderer extends DefaultFormRenderer
{
public $wrappers = array(
'form' => array(
public $wrappers = [
'form' => [
'container' => null,
),
'error' => array(
],
'error' => [
'container' => 'div class="alert alert-danger"',
'item' => 'p',
),
'group' => array(
],
'group' => [
'container' => 'fieldset',
'label' => 'legend',
'description' => 'p',
),
'controls' => array(
],
'controls' => [
'container' => null,
),
'pair' => array(
],
'pair' => [
'container' => 'div class=form-group',
'.required' => 'required',
'.optional' => null,
'.odd' => null,
'.error' => 'has-error',
),
'control' => array(
],
'control' => [
'container' => '',
'.odd' => null,
'description' => 'span class=help-block',
Expand All @@ -45,51 +51,45 @@ class BootstrapVerticalRenderer extends DefaultFormRenderer
'.submit' => 'button',
'.image' => 'imagebutton',
'.button' => 'button',
),
'label' => array(
],
'label' => [
'container' => '',
'suffix' => null,
'requiredsuffix' => '',
),
'hidden' => array(
],
'hidden' => [
'container' => 'div',
),
);
],
];

/** @var bool */
private $novalidate;

public function __construct($novalidate = true)
public function __construct(bool $novalidate = true)
{
$this->novalidate = $novalidate;
}

/**
* Provides complete form rendering.
* @param Nette\Forms\Form
* @param string 'begin', 'errors', 'ownerrors', 'body', 'end' or empty to render all
* @return string
*/
public function render(Nette\Forms\Form $form, $mode = null)
public function render(Form $form, string $mode = null): string
{
if ($this->novalidate) {
$form->getElementPrototype()->setNovalidate('novalidate');
}

$usedPrimary = FALSE;
$usedPrimary = false;
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
if (strpos($control->getControlPrototype()->getClass(), 'btn') === FALSE) {
if ($control instanceof 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) {
} elseif ($control instanceof TextBase ||
$control instanceof SelectBox ||
$control instanceof MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox ||
$control instanceof Controls\CheckboxList ||
$control instanceof Controls\RadioList) {
} elseif ($control instanceof Checkbox ||
$control instanceof CheckboxList ||
$control instanceof RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
Expand Down

0 comments on commit 174f04d

Please sign in to comment.