Exemple #1
0
 public function __invoke(Tag $tag, Renderer $renderer)
 {
     if ($tag instanceof AbstractWidget && $tag->getInput()) {
         $this->addInputIdAttribute($tag, $renderer);
         $this->addLabelForAttribute($tag, $renderer);
     }
     return $tag;
 }
Exemple #2
0
 function render()
 {
     $classes = $this->get('_classes');
     $field = $this->get('_field');
     $this->set('class', $classes['form_group']);
     $this->setContent(array($this->builder->make('label', array('class' => $classes['form_label']), $field['label']), $this->builder->make('text', array('class' => $classes['form_control']), $field['value'])));
     return parent::render();
 }
 function __construct($props = null, $content = null, \Sirius\Html\Builder $builder)
 {
     parent::__construct($props, $content, $builder);
     $classes = $this->get('_classes');
     $field = $this->get('_field');
     $this->set('class', $classes['form_group']);
     $this->setContent(array($this->builder->make('label', array('class' => $classes['form_label']), $field['label']), $this->builder->make('text', array('class' => $classes['form_control']), $field['value'])));
 }
 public function __invoke(Tag $tag, Renderer $renderer)
 {
     if ($tag instanceof Form) {
         $tag->addClass('form-horizontal');
     }
     if ($tag instanceof AbstractWidget && !$tag instanceof Group && $tag->getLabel() && $tag->getInput()) {
         $tag->getLabel()->addClass('col-sm-3');
         $tag->getInput()->wrap('<div class="col-sm-9">', '</div>');
         if ($tag->getHint()) {
             $tag->getHint()->addClass('col-sm-9 col-sm-push-3');
         }
     }
     return $tag;
 }
 /**
  * @param mixed $props
  * @param mixed $content
  * @param Renderer $builder
  */
 public function __construct($props = null, $content = null, Renderer $builder = null)
 {
     if (!$builder) {
         throw new \InvalidArgumentException('The forms renderer widgets require a Renderer object');
     }
     parent::__construct($props, $content, $builder);
     $this->createLabel();
     $this->createHint();
     $this->createError();
     $this->createInput();
 }
    protected function appendScript(Tag $tag, Renderer $renderer)
    {
        /* @var $form \Sirius\Input\InputFilter */
        $form = $tag->get('_form');
        $rules = array();
        $messages = array();
        foreach ($form->getValidator()->getRules() as $selector => $valueValidator) {
            /* @var $valueValidator \Sirius\Validation\ValueValidator */
            foreach ($valueValidator->getRules() as $rule) {
                /* @var $rule \Sirius\Validation\Rule\AbstractRule */
                $clientSideRule = $this->getClientSideRule($rule);
                if ($clientSideRule) {
                    $rules[$selector][$clientSideRule['name']] = $clientSideRule['options'];
                    $messages[$selector][$clientSideRule['name']] = $rule->getPotentialMessage()->__toString();
                }
            }
        }
        if (!$tag->get('id')) {
            $tag->set('id', 'f' . rand(1, 1000));
        }
        $formId = $tag->get('id');
        $rules = json_encode($rules);
        $messages = json_encode($messages);
        $script = <<<JSCRIPT
<script>
jQuery && jQuery('#{$formId}').validate({
    rules: {$rules},
    messages: {$messages},
    errorElement: 'div',
    errorClass: 'error',
    errorPlacement: function(error, element) {
        // Append error within linked label
        error.addClass('alert alert-danger');
        \$( element ).closest( ".form-group" ).prepend( error );
    },
});
</script>
JSCRIPT;
        $tag->after($script);
    }
 protected function addWidgetClass(Tag $tag)
 {
     if ($tag instanceof AbstractWidget && !$tag instanceof Form && !$tag instanceof Group) {
         $tag->addClass('form-group');
     }
 }
 protected function translateButton(Tag $tag, Renderer $renderer)
 {
     $tag->setContent($this->getStringTranslation($tag->getContent()[0], $renderer->getOption('language')));
 }