Form {input} doesn't render attributes

Notice: This thread is very old.
livioribeiro
Member | 7
+
0
-

I'm trying to create a form with twitter bootstrap style. The form inputs require the class .form-control to be set on the <input> elements. I'm doing this:

{form username class => "form-control"}

but the class isn't rendered in the input element.

Majkl578
Moderator | 1364
+
0
-

This will set the class on <form> tag, nowhere else.

livioribeiro
Member | 7
+
0
-

Sorry, that was a typo, the correct was {input username class => "form-control"}.

I created a template templates/components/bsform.latte with the following content:

<?php
{form $form}
<ul class=error n:if="$form->ownErrors">
	<li n:foreach="$form->ownErrors as $error">{$error}</li>
</ul>

<div n:foreach="$form->controls as $input" n:class="$input->required ? required, form-group">
	{label $input /}
	{input $input class => 'form-control'}
    <span class="error" n:ifcontent>{$input->error}</span>
</div>
{/form}
?>

and called it from templates/Sign/in.latte:

<?php
{block content}
<h1 n:block=title>Sign in</h1>

{include '../components/bsform.latte', form => signInForm}
?>

This way the class is not set on the inputs

Jan Tvrdík
Nette guru | 2595
+
0
-

This should definitely work. See the official example.

livioribeiro
Member | 7
+
0
-

The {input $input class => 'form-control'} renders correctly if I put the form directly on the template I want to show it, but the class attribute is not set if I use it as a component and call from another page using {include '../components/bsform.latte', form => signInForm}

livioribeiro
Member | 7
+
0
-

I tested on other computer and it worked, don't know what happened.

Thanks for the quick responses.