How to implement jquery date time picker with zend framework 2 using zf FORM - zend-framework

Thanks in advance,
Want to implement jquery date time picker with zend framework 2 using ZF FORM, with validation of form date selection depending on to date.
Please suggest the best practice.

You can proceed as follows
In your form you add a date field:
$this->add([
'name' => 'birthDate',
'type' => 'Zend\Form\Element\Date',
'attributes' => [
'id' => 'birthDate',
'class' => 'required datepicker-date',
'type' => 'text'
],
'options' => [
'label' => 'Birth date'
]
]);
notice the 'type' => 'text'.
Then in the view you print the form element as you please and add the following javascript snippet:
$(document).ready(function() {
$( ".datepicker-date" ).datepicker({
dateFormat: "dd-mm-yy",
changeMonth: true,
changeYear: true
});
});
Adjust the options according to your needs.

You can do it by using bootstrap-datepicker
So firstly you want to insert following CSS and JS files.Those are
1.bootstrap.css
2.bootstrap-datetimepicker.min.css
3.jquery.min.js
4.bootstrap-datepicker.min.js
<script type="text/javascript">
$(document).ready(function() {
$('#yourTextFieldIDName').datepicker({
format: "yyyy-mm-dd",
viewMode: "day",
minViewMode: 'day'
});
</script>

Related

Remove tooltip from kartik/date/datepicker

I use kartik DatePicker in my activeform.
use kartik\date\DatePicker;
My activeform field:
<?= $form->field($model, 'transferred_date')->widget(DatePicker::className(), [
'value' => date('d-M-Y', strtotime('+2 days')),
'options' => ['placeholder' => 'Select date ...'],
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'todayHighlight' => true
]
])->label('Transferred Date');
?>
When I hover the mouse on calendar icon, it shows a tool tip like this.
I have to remove the tooltip. How can I?
When reading the doc you can read this in the settings:
pickerButton: mixed the calendar picker button configuration - applicable only when type is set to DatePicker::TYPE_COMPONENT_PREPEND or DatePicker::TYPE_COMPONENT_APPEND. This can be one of the following types:
string, if this is a string, it will be displayed as is (and will not be HTML encoded).
boolean, if this is set to false, it will not be displayed.
array, this is the default behavior. If passed as an array, it will be considered as HTML attributes for the picker button addon. The following special keys are recognized:
icon, string the bootstrap glyphicon name/suffix. Defaults to 'calendar'.
title, string|boolean the title to be displayed on hover. Defaults to 'Select date & time'. If this is set to false, it will not be displayed.
So i can say without testing that it should be something like this:
<?= $form->field($model, 'transferred_date')
->widget(DatePicker::className(), [
'type' => DatePicker::TYPE_COMPONENT_PREPEND,
'pickerButton' => ['title' => false],
'value' => date('d-M-Y', strtotime('+2 days')),
'options' => ['placeholder' => 'Select date ...'],
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'todayHighlight' => true
]
])->label('Transferred Date');
?>
So you missed this in the config:
'type' => DatePicker::TYPE_COMPONENT_PREPEND,
'pickerButton' => ['title' => false],

Symfony: Hide/Show form element dependent on dropdown selection with database entries

I hope my title is proper: I have a dropdown, that comes from a form as an EntityType and the values are from an entity class. Code:
->add('type', EntityType::class, array(
'class' => 'DocumentBundle:DocumentType',
'label' => 'label.type',
'property' => 'translationKey',
'required' => true,
'multiple' => false,
'expanded' => false,
'empty_value' => 'label.select_type',
'choice_translation_domain' => 'Documents'
))
->add('vka_number', 'text', array(
'label' => 'label.vka_number',
'required' => false,
'translation_domain' => 'Documents'))
the second one is a text field (vka_number) that I only want to be shown when a specific value from that dropdown is selected
in my twig template I render the elements:
<div class="row">
<div class="col-md-6" id="documentDropdown">
{{ form_row(form.type) }}
</div>
<div class="col-md-6" id="vka">
{{ form_row(form.vka_number) }}
</div>
</div>
I was thinking about a javascript function like that:
<script>
$(document).ready(function(){
$('#documentDropdown').on('change', function(){
if (this.value == 'Contract')
{
$('#vka').show();
}
else {
$('#vka').hide();
}
});
});
</script>
but it's not working and I think this is because it can't access the values from the dropdown since they are not hard coded but database entries.
'Contract' would be the entry (id=1) that "makes" the vka_number text field appear.
I copied the html code from your previous question Sonja, and you seem to be continuing to ask the same question. I used that code in this jsfiddle:
https://jsfiddle.net/alvinbunk/to9qodwx/
You can use jsfiddle to experiment with your jQuery code to figure out what is wrong. As you can see the code does work and does hide the vka id division. it really has nothing to do with the fact that values are from the database. Make sure you don't have duplicate ids in various elements in your html code. Use "view source" in your browser to see the rendered code.
By the way I spent at least 15 minutes on this answer, and also 15 - 30 minutes on the other one. be aware that people on StackOverflow are very busy, and it's good to ask your questions very clearly.
EDIT #2 - Based on comments
Use this jQuery code:
<script>
$(document).ready(function(){
$('#documentDropdown').on('change', function(){
if (this.value == '1')
{
$('#vka').show();
}
else {
$('#vka').hide();
}
});
});
</script>
That should work.
Here's my javascript function that eventually solved my problem.
$(document).ready(function () {
$('#type ').change(function() {
if ($('select[id$="_type"]>option:selected').text() == "Contract") {
$('#vka_number ').show();
}
else {
$('#vka_number').hide();
}
});
});

how to disable breadcrumb for some controllers yii2?

I want disable or change breadcrumb in Yii2 application. How to do that.I
tried to change with
echo Breadcrumbs::widget([
'itemTemplate' => "<li><i>{link}</i></li>\n", // template for all links
'links' => [
[
'label' => 'Post Category',
'url' => ['post-category/view', 'id' => 10],
'template' => "<li><b>{link}</b></li>\n", // template for this link only
],
['label' => 'Sample Post', 'url' => ['post/edit', 'id' => 1]],
'Edit',
],
]);
Well, first of all change it back to default, which is:
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
According to yii2 documentation if you set the value for $links to an empty array, breadcrumbs will not show up.
How do you do it?
Check above code , the $links value in being set by $this->params['breadcrumbs'] variable, which is available in every view file. So in your view file just do this:
// empty if you don't want breadcrumbs
$this->params['breadcrumbs'] = [];
Otherwise set some value and your breadcrumbs will show up.

How to set place holder copy in date select menu in CakePHP

I am using CakePHP 1.3 to create a select menu for date of birth (as below). I can set the default starting values as either blank or a selected date, but ideally I would like to have DD-MM-YYYY as the starting displayed values:
echo $form->input('dob',
array(
'before' => '',
'between' => '',
'after' => '',
'label' => false,
'divider' => false,
'monthNames' => false,
'selected' => false,
'empty' => true,
'dateFormat' => 'DMY',
'minYear' => date('Y') - 70,
'maxYear' => date('Y') - 16,
'error' => array('wrap' => 'div', 'class' => 'error-copy')
));
What I get:
What I would like:
Thank you
I believe if you want to do this you will have to make your own date fields and not use the FormHelper since you can only set a default date to it, what you want involves adding an element to the fields.
You could also try JQuery's datepicker out, it's what I use in my project, and since it's a text field you can just set whatever you want as a placeholder.
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
echo $this->Form->dateTime('Contact.date', 'DMY', '12',
array(
'empty' => array(
'day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
)
)
);
I believe you can only set a default date on the date fields.
echo $this->Form->input('close_time', array('type' => 'time', 'selected' => '13:30:00'));
Cookbook entry
For the benefit of anyone Googling to find the answer to this question 1+ years after it was asked, we can now simply do the following to set default placeholder (temporary) values in CakePHP forms that are easily replaced when clicked:
<?php echo $this->Form->input('Email', array(
'placeholder'=>'Enter Your Email Here'
)); ?>
I like to include 'label' => false as well to make the forms really minimalist.

How to apply click event for option button using Zend form

I am new to zend, Below is my piece of code,
$TEST = new Zend_Form_Element_Radio('test', array(
'label' => 'Send:*',
'value' => $data,
'multiOptions' => array(0 => 'TEST1', 1 => 'TEST2',2 => 'TEST3 '),
));
$this->addElement($TEST);
Here i Want to apply onclick event for above 3 option button respectively.Is it possible ?.Kindly help me on this
You would probably be best off using jQuery for this? E.g.:
$(function() {
$("#test").click(function(){
// whatever you need to do
});
});