I am new to zendframework2. I wanna to insert time from time picker. I did a lot of practice, but time picker is not displayed when clicking on form field for selecting time..
form:
$this->add(array(
'type' => 'Zend\Form\Element\Time',
'name' => 'departure_time',
'attributes' => array(
'id' => 'departure_time',
'required' => 'required',
'type' => 'text',
),
'options' => array(
'label' => 'Departure Time ',
),
));
view :
echo $this->form()->openTag($form);
echo $this->formRow($form->get('departure_time'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
<script type="text/javascript">
$(document).ready(function() {
$( ".departure_time" ).datepicker({
dateFormat: "dd-mm-yy",
changeMonth: true,
changeYear: true
});
});
</script>
Is there need to call jquery function through onclick event from form.
Thanks in advance. Please
It looks like you are passing the wrong selector string into your jQuery function.
Since you have
'id' => 'departure_time',
It should be:
<script type="text/javascript">
$(document).ready(function() {
$( "#departure_time" ).datepicker({
dateFormat: "dd-mm-yy",
changeMonth: true,
changeYear: true
});
});
</script>
Or you need to add class of departure_time to your ZF2 form config
**** UPDATE ****
You can add a class the same way as an id, for your code it would be:
$this->add(array(
'type' => 'Zend\Form\Element\Time',
'name' => 'departure_time',
'attributes' => array(
'class' => 'departure_time',
'required' => 'required',
'type' => 'text',
),
'options' => array(
'label' => 'Departure Time ',
),
));
Related
I'm developing a prestashop module.in my controller renderForm i have drop down list to load week days.but it showing only first letter of the day.
public function renderForm() {
$days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
'input' => [
[
'type' => 'select',
'lang' => true,
'required' => true,
'label' => $this->l('WeekDay'),
'name' => 'weekday',
'options' => [
'query' => $days,
],
],
]
}
Showing like this
Inspect Element
Your query value should be like below format as per prestashop 1.7 documentation.
$days = array(
array(
'id' => 1, // The value of the 'value' attribute of the <option> tag.
'name' => $this->trans('Monday', array(), 'Admin.International.Feature') // The value of the text content of the <option> tag.
),
array(
'id' => 2,
'name' => $this->trans('Tuesday', array(), 'Admin.International.Feature')
),
);
I'm trying to use a jquery datetimepicker.
And I have some trouble when I submit the form:
This value is not valid. : Unable to reverse value for property path "debut": Date parsing failed: U_PARSE_ERROR
Here is my form:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('debut', 'datetime', array(
'widget' => 'single_text',
'label' => 'Debut',
'html5' => false,
'format' => 'dd/MM/yyyy H:m'
))
//...
And the javascript is:
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.full.min.js"></script>
<script>
$(document).ready(function () {
$( '#mybundle_evenement_debut' ).datetimepicker({
startDate: new Date(),
format: 'd/m/y H:i',
autoclose: true,
});
});
</script>
How would you fix this?
I have following code in my view file:
<?= $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'time',
'language' => 'ru',
'htmlOptions' => array(
'size' => '10',
'class' => 'form-control form_empty centered date',
),
'options' => array(
'dateFormat' => 'dd/mm/yy',
'showOn' => 'focus',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
'closeText' => Yii::t('ablock', 'Очистить'),
'beforeShow' => 'js:
function( input ) {
setTimeout(function() {
var clearButton = $(input ).datepicker( "widget" ).find( ".ui-datepicker-close" );
clearButton.unbind("click").bind("click",function(){ $.datepicker._clearDate( input );});
}, 1 )}',
),
),
true) ?>
I used this code in order to allow user to enter date. However, it is accepting 0 values. For example, if user enters incomplete date such as 0d/mm/yyyy (which is incorret date), it will accept it as true. I need to not allow, if user enters wrong value. How can I do it?
I haven't found any params for accepting only complete dates. Suggested workarounds:
AJAX validation for the date field in your model
disable field input, so the user is limited to the datepicker
perform validation via overriding date method (see example: https://stackoverflow.com/a/21898124/5992898)
I have the following code which allow users to add order details. And I'm using the datapicker jQuery to display a calendar for dates. For example, the order date field, I want to prevent users from choosing a future date. How can I do that?
My code is as follows:
edit.ctp:
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1950:2020',
dateFormat: "yy-mm-dd"
});
$("#datepicker2").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1950:2020',
dateFormat: "yy-mm-dd"
});
});
</script>
</head>
<?php
$usertype = $this->SESSION->read('User.usertype');
?>
<body>
<div class="orders form">
<?php echo $this->Form->create('Order'); ?>
<fieldset>
<legend><?php echo __('Edit Order Details'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('invoice_number', array('required' => false));
echo $this->Form->input('order_date', array('required' => false, 'id' => 'datepicker', 'type' => 'text'));
echo $this->Form->input('payment_type', array('required' => false, 'options' => array('Cash' => 'Cash', 'EFTPOS' => 'EFTPOS', 'CC' => 'CC', 'Cheque' => 'Cheque', 'PayPal' => 'PayPal'), 'empty' => '(choose one)'));
echo $this->Form->input('order_type', array('required' => false, 'options' => array('Email' => 'Email', 'Telephone' => 'Telephone', 'Web' => 'Web'), 'empty' => '(choose one)'));
echo $this->Form->input('date_promised', array('required' => false, 'id' => 'datepicker2', 'type' => 'text'));
echo $this->Form->input('order_description', array('required' => false));
echo $this->Form->input('order_comments', array('required' => false));
echo $this->Form->input('order_total', array('required' => false));
echo $this->Form->input('amount_deposited', array('required' => false));
echo $this->Form->input('balance_due', array('required' => false));
/* echo $this->Form->input('customers_id', array('required'=>false));
echo $this->Form->input('employees_id', array('required'=>false));
*/
echo $this->Form->input('customers_id', array('label' => 'Customer Name', 'options' => $customers, 'label' => 'Customer Name', 'required' => false));
echo $this->Form->input('employees_id', array('label' => 'Employee name', 'options' => $employees, 'label' => 'Employee name', 'required' => false));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div
</body>
</html>
Can someone please help?
try this
$(function() { $("#datepicker").datepicker({
maxDate: '0'});
});
This will set the maxDate to +0 days from the current date (i.e. today).
Here is the reference
fiddle:
http://jsfiddle.net/pvXzb/
jquery:
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1950:2020',
dateFormat: "yy-mm-dd",
maxDate: 0
});
I am trying to get the IDs of all the selected check boxes in yii using JAVASCRIPT. Now i am able to get only the first element ID. Can anyone please suggest the correct code to get all the check box ID.
My View:
<input type="button" value="Multiple Host Date Entries" onclick="act();" />
<div id="grid"></div>
<?php
//zii.widgets.grid.CGridView bootstrap.widgets.TbExtendedGridView
$obj=$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'host_grid',
'dataProvider'=>$dataProvider,
'type' => 'striped bordered',
//'filter' => $model,
//'type' => 'striped bordered condensed',
//'summaryText' => false,
////'afterAjaxUpdate'=>'\'changeTRColor()\'',
//'itemView'=>'_view',
'columns'=>array(
array(
'id' => 'selectedIds',
'class' => 'CCheckBoxColumn',
'selectableRows'=>2,
'value' => '$data->host_id',
'checkBoxHtmlOptions' => array('name' => 'idList[]'),
),
array( // display 'create_time' using an expression
'name'=>'host_name',
'value'=>'$data->host_name',
),
array(
'name'=>'host_serviceid',
'value'=>'$data->host_serviceid',
),
array(
'name'=>'status',
'value'=>'$data->status',
),
array(
'class'=>'CButtonColumn',
'template'=>'{edit_date}{update}{delete}',
'htmlOptions'=>array('width'=>'95px'),
'buttons' => array(
'update'=> array(
'label' => 'Update',
'imageUrl' => Yii::app()->baseUrl.'/images/icons/a.png',
),
'delete'=> array(
'label' => 'Delete',
'imageUrl' => Yii::app()->baseUrl.'/images/icons/d.png',
),
'edit_date' => array( //the name {reply} must be same
'label' => 'Add Date', // text label of the button
'url' => 'Yii::app()->createAbsoluteUrl("NimsoftHostsDetails/View", array("id"=>$data->host_id))', //Your URL According to your wish
'imageUrl' => Yii::app()->baseUrl.'/images/icons/m.png', // image URL of the button. If not set or false, a text link is used, The image must be 16X16 pixels
),
),)
),
))
;
?>
I must select some check boxes and click on multiple host date entries button to go to the specific controller.
My JavaScript:
function act()
{
var idList=$("input[type=checkbox]:checked").serializeArray();
var jsonStr = JSON.stringify(idList);
/* Object.keys(idList).forEach(function(key) {
console.log(key, idList[key]);
alert(idList[key]);
});*/
var a=$("input[type=checkbox]:checked").val();
alert(a);
if(idList!="")
{
if(confirm("Add Dates for multiple hosts?"))
{
var url='<?php echo $this->createUrl('Nimsoft/Date_all',array('idList'=>'val_idList')); ?>';
url=url.replace('val_idList',jsonStr);
//url=url.replace('val_idList',json_encode(idList));
//alert(url);
window.open(url);
/*$.post('Date_all',idList,function(response)
{
$.fn.yiiGridView.update("host_grid");
});*/
}
}
else
{
alert("Please Select atleast one host");
}
}
I need to pass the IDs to NIMSOFT controller so that I can have a for loop to process each one of those.
you can retrieve the checked column in client side (javasctipt):
var idArray = $(gridID).yiiGridView('getChecked', columnID);
// or
$.fn.yiiGridView.getSelection(gridID);
For all checked row ids we use this
var id = $.fn.yiiGridView.getChecked("your-grid-id", "selectedIds"); // array of seleted id's from grid