I am starting to use the Yii2 Kartik helpers.
The issue i am having is the CSS of the datepicker
As you can see the Date of Birth field has no padding at the bottom.
The code for the fields around it
<?= $form->field($model, 'mobile')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'telephone')->textInput(['maxlength' => true]) ?>
<?= Html::activeLabel($model, 'date_of_birth') ?>
<?= DatePicker::widget([
'model' => $model,
'attribute' => 'date_of_birth',
'options' => ['placeholder' => 'Enter birth date ...'],
'pluginOptions' => [
'autoclose'=>true,
'format' => 'dd-mm-yyyy',
]
]); ?>
<?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'user_id')->textInput() ?>
From the CSS i can see that the Kartik creates a div with the class input-group
<div id="staff-date_of_birth-kvdate" class="input-group date">
Where as the standard form element have a div with the class form-group
<div class="form-group field-staff-telephone">
Any ideas?
Regards
Liam
You should simply try :
<?= $form->field($model, 'date_of_birth')->widget(DatePicker::className(), [
'options' => ['placeholder' => 'Enter birth date ...'],
'pluginOptions' => [
'autoclose'=>true,
'format' => 'dd-mm-yyyy',
],
]) ?>
Read more : http://demos.krajee.com/widget-details/datepicker#usage
Related
I am making form in symfony, I create a select box product in ProductType.php :
$form->add(
'product',
ChoiceType::class,
[
'choices' => array_flip($product),
'label' => 'Product',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control film-list not-chosen'],
'placeholder' => '-- Select product --',
'multiple' => false,
'required' => false
]
);
in View :
<?php echo $view['form']->start($form); ?>
<div class="col-md-12">
<div class="row">
<div class="col-md-6">
<?php echo $view['form']->row($form['product']); ?>
</div>
</div>
</div>
<?php echo $view['form']->end($form);
And it shows successfully on the theme. But my theme uses modal of bootstrap. When shown above, my select box is changed to readonly, cannot enter keywords. Where did I go wrong. Please everyone help me.
Update:
I have added 'readonly' => false to attr in the form but it still doesn't work.
If I set post-status to 'publish' (as shown below) this form creates the post, but my acf fields for this post type (some should be auto-populated) aren't added to the database
If I set post-status to 'draft' this form creates the draft - if I edit and save that draft all is good
Any ideas?
Thanks, Richard
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary" class="rs-add-forms">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'new_post' => array(
'post_type' => 'people',
'post_status' => 'publish'
),
'fields' => array('field_5ed5c2215be79',),
'submit_value' => 'Create Person',
'html_submit_button' => '<input type="submit" class="rs-add-button" value="%s" />',
'updated_message' => false
)); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
Since acf_form calls acf_add_local_field on the value of the fields key in the options array, you should try structuring your data like the function parses defaults for, internally.
// Apply default properties needed for import.
$field = wp_parse_args($field, array(
'key' => '',
'name' => '',
'type' => '',
'parent' => '',
));
Therefore, you might modify to
'fields' => array(
array(
'key' => 'field_5ed5c2215be79',
'name' => 'Form Field Title',
'type' => 'registered_acf_fieldtype',
'parent' => '[probably optional]'
)
),
Im beginning with both bootstrap and CakePHP 2.x. I baked my views with https://github.com/EKOInternetMarketing/BootstrapCake but there is a problem with date-fields layout. The view looks like this
<div class="form-group">
<?php echo $this->Form->input('booking_date', array('class' => 'form-control', 'placeholder' => 'Booking Date'));?>
</div>
But the problem is that CakePHP creates three selects from a date-field which are all 100% width, which messes up the form and the fields look like this, while it should be three selects side-by-side:
Apparently bootstrap 2 had classes for smaller selects, but bootstrap 3 doesnt anymore. Any ideas how to get it looking like it should?
For cakephp3, you have to do things a little differently:
echo $this->Form->input('booking_date', ['year' => ['class' => 'form-control'], 'month' => ['class' => 'form-control'], 'day' => ['class' => 'form-control'] ]);
http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-datetime-inputs
For input of type date in CakePHP you aren't able to wrap each select element by tag you like in standard way using div option, but there is 3 options which can handle it - between, separator and after. Below is example which set your selects inline.
<div class="form-group">
<?php echo $this->Form->input('booking_date', array(
'class' => 'form-control',
'placeholder' => 'Booking Date',
'div' => array('class' => 'form-inline'),
'between' => '<div class="form-group">',
'separator' => '</div><div class="form-group">',
'after' => '</div>'
));?>
</div>
If you using bootstrap grid you can get even better result using its classes to set this selects inline.
This is my form code
$this->add(array(
'name' => 'abc',
'type' => 'TextArea',
'options' => array(
'label' => _('Enter description'),
),
'attributes' => array(
'rows' => '1',
'cols' =>'75',
)
));
This is my view code
<?php echo $this->formLabel($form->get('abc'))."<br>"; ?>
<?php echo $this->formInput($form->get('abc'))."<br>"; ?>
The problem here is that I don't get a TextArea and instead get a normal textbox. It was working when I used the code
<?php echo $this->formRow($form->get('abc'))."<br>"; ?>
When I try to print label and input separately, It is not using its type and attributes. How can I correct this for my case.
use in your view the zend view helper formText to print a textarea
echo $this->formText($form->get('abc'))
in your form class use as type => Zend\Form\Element\Text
http://framework.zend.com/manual/2.0/en/modules/zend.form.view.helpers.html
I'm attempting to set the class on a class on a form label using php templates.
Here's my code:
<?php echo $view['form']->label($form['first_name'], 'First Name', array(
'attr' => array('class' => 'control-label')
)) ?>
But here's my output:
<label class="required" for="form_first_name">First name</label>
I can find how to do it using twig, but not an example with PHP.
I've got it...
<?php
echo $view['form']->label($form['first_name'], 'First Name', array(
'label_attr' => array('class' => 'control-label'),
))
?>
Apparently "attr" is "label_attr" for labels fields.
P.S. Corresponding twig code
{{ form_label(form.first_name, 'First Name', { 'label_attr': {'class': 'control-label'} }) }}