I want to create forms in symfony2. I need this HTML structur for each control.
<div class="form-group">
<label class="col-md-2 control-label">Firstname:</label>
<div class="col-md-10"><input type="text" name="firstname" class="form-control">/div>
</div>
Now is my question, how can i add the div with the class form-group and how can i surround the input element with the div .col-md-10?
$builder->add('firstname', 'text', array(
'attr' => array(
'class' => 'form-control'),
'label_attr' => array(
'class' => 'col-md-2 control-label'
)
)
);
Check How to customize Form Rendering section of the documentation.
You may need to override the form_widget block (form_widget_compound block to go into details).
Find here the default behavior of each twig form helper.
The Form Theming Sub Chapter contains many relevant examples on how to customize any given form field block.
Related
I have the HTML code like this:
<label>Main Text (<span class="main_text_count">0</span><span>) Characters</span></label>
<textarea name="data[News][sentence]" id="main_text" class="form-control" required rows="8"></textarea>
And I don't know how to create a text area like this, using Form helper of cakePHP.
Simply done using the Form Helper (both for CakePHP 2 and CakePHP 3):-
echo $this->Form->textarea(
'News.sentence',
[
'id' => 'main_text',
'class' => 'form-control',
'rows' => 8,
'label' => 'Main Text (<span class="main_text_count">0</span><span>) Characters</span>'
]
);
In future make sure you've fully read Cake's documentation.
I use the kendo ui mvc grid.
I set the columns to Editable(false);
I can still edit those fields in the popup editing dialog. Why?
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.FirstName).Editable(false);
model.Field(p => p.LastName).Editable(false);
}
)
Popups always has to be customized.
In Views > Shared > EditorTemplates > Person (or whatever your class is) you just toss in whatever you want
#model TelerikMvcApp1.Models.Foo.Person
<div>
#Html.HiddenFor(person => person.Id)
<div class="editor-label">
<label for="Title">First Name</label>
</div>
<div class="editor-field">
#Html.Kendo().TextBoxFor(person => person.FirstName)
</div>
</div>
When i am adding form to view & specifying parameters as
<?= $form->field($model, 'form_name', ['options' => ['id' => 'formName', 'name' => 'formName']])->textInput(); ?>
But, when i run in the browser & check for view page source, there it shows me
<input type="text" id="submitform-form_name" class="form-control" name="SubmitForm[form_name]">
this disturbs my javascript calling for field input. How to stop yii2 from generating its own id???
You are passing options to ActiveField. If you want override id and name attributes, pass them in textInput() options like so:
<?= $form->field($model, 'form_name')->textInput(['id' => 'formName', 'name' => 'formName']) ?>
Generated html output will be:
<input type="text" name="formName" class="form-control" id="formName">
Note that after that client validation for this attribute will stop working and that attribute won't be massively assigned.
I would like to combine the Laravel model binding properties with the easy jQuery Validation plugin, if that is possible.
I can't figure out how to add the 'required' attribute to the blade syntax.
Here is normal form syntax with the "required" attribute:
<input type="text" name="title" required>
Laravel Blade syntax
{{ Form:: text('title', null, array('class' => 'form-control')) }}
Any help would be appreciated.
required is a normal HTML input attribute. The only difference is that it doesn't have different values -- it's either present or it's not, which makes it the so-called boolean attribute.
Anyway, this should do the trick:
{{ Form:: text('title', null, array('class' => 'form-control', 'required' => '')) }}
See more here.
My goal is to let ZendForm generate my form in this way:
a DIV wrapper that include the normal DD and DT Zend tag... My DIV need to have the ID tag with the id of the element like this:
<dl>
<div id="65-div">
<dt id="65-label"><label for="65" class="required">Nome</label></dt>
<dd id="65-element">
<input type="text" name="65" id="65" value="">
</dd>
</div>
<div id="66-div">
...... ...
</div>
</dl>
I was able to reach my goal doing that:
$Element = $this->createElement('text', $result->request_field__ID);
$Element->clearDecorators()
->addDecorator('ViewHelper')
->addDecorator('Errors')
->addDecorator(array('data'=>'HtmlTag'), array('tag' => 'dd', 'id' => $Element->getId() . '-div', 'class' => 'zendData'))
->addDecorator(array('labelDivOpen' => 'HtmlTag'), array('tag' => 'dt', 'placement' => 'prepend', 'closeOnly' => true))
->addDecorator('Label')
->addDecorator(array('labelDivClose' => 'HtmlTag'), array('tag' => 'dt', 'id' => $Element->getId() . '-label', 'class'=>'zendLabel','placement' => 'prepend', 'openOnly' => true))
->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div', 'id' => $Element->getId() . '-div'));
Is this the best way?
Why I'm doing that?
Because I generate my form dinamically... And I want to hide some fields and then display it with Jquery if some conditions happend...
In order to hide my field I use:
$Element->getDecorator('row')->setOptions(array('style' => 'display:none;'));
Is this also the best way?
This doesn't look like valid HTML to me. You'd be much better off dropping the divs and using the IDs on the dt and dd that are already there, so just display none those when you want to hide an element. Also, IDs cannot start with a number, so you might want to reverse your naming scheme so that it's element-65 instead.