Created
July 29, 2013 13:44
-
-
Save hrach/6104393 to your computer and use it in GitHub Desktop.
FormMacros customization of Bootstrap3 macro (for Nette framework).
See https://github.com/nextras/forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* signaly.cz - christian community platform | |
* MIT license | |
* | |
* @link https://www.signaly.cz | |
*/ | |
namespace Signaly; | |
use Nette; | |
use Nette\Latte; | |
use Nette\Utils\Html; | |
use Nette\Forms\Controls; | |
use Nextras\Forms\Bridges\Latte\Macros\BS3InputMacros; | |
class FormMacros extends BS3InputMacros | |
{ | |
public static function install(Latte\Compiler $compiler) | |
{ | |
$me = parent::install($compiler); | |
$me->addMacro('labelText', 'echo $_label->setName(NULL)->render();'); | |
$me->addMacro('formErrors', 'echo Signaly\FormMacros::formErrors($_form->getErrors());'); | |
$me->addMacro('formAllErrors', 'echo Signaly\FormMacros::formErrors($_form->getAllErrors());'); | |
} | |
public static function label(Html $label, Controls\BaseControl $control) | |
{ | |
$label = parent::label($label, $control); | |
if ($label->getName() === 'label') { | |
if (!$control->getOption('required')) { | |
$label->addClass('optional'); | |
if (!empty($label->optional)) { | |
unset($label->optional); | |
$label->add('<small>nepovinné</small>'); | |
} | |
} | |
} | |
return $label; | |
} | |
public static function input(Html $input, Controls\BaseControl $control) | |
{ | |
$input = parent::input($input, $control); | |
if ($input->getName() === 'button') { | |
$input->addClass('btn-primary'); | |
} | |
return $input; | |
} | |
public static function formErrors($errors) | |
{ | |
foreach ($errors as $error) { | |
echo '<p class="message-error">' . Nette\Templating\Helpers::escapeHtml($error, ENT_NOQUOTES) . '</p>'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment