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?
Related
I am using pikaday.js date picker.
I have moment.js loaded as well.
If i select 02/02/2022 it stored fine but when the page loads it changes changes the date to a random date.
var qualExpiry = new Pikaday({
field: document.getElementById('qualExpiry'),
firstDay: 1,
format: 'DD-MM-YYYY',
yearRange: [2010, 2040]
});
{!! Form::text('expiry_date', null, ['id' => 'qualExpiry', 'class' => 'form-control form-control-lg form-control-solid mb-3 mb-lg-0', 'placeholder' => 'Select expiry date']) !!}
if i remove format: 'DD-MM-YYYY' and use the default ISO format it works fine
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 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 ',
),
));
I'm developing a small app with CakePHP and I need to save a startdate and an enddate for an event. I went with the Bootstrap Daterangepicker to let users visually input the dates.
In my add.ctp view I have two fields:
<div class="form-group">
<?php echo $this->Form->input('start', array(
'class' => 'form-control',
'type' => 'text',
'id' => 'start',
'name' => 'start',
'data-mask')); ?>
</div><!-- .form-group -->
<div class="form-group">
<?php echo $this->Form->input('end', array(
'class' => 'form-control',
'type' => 'text',
'id' => 'end',
'name' => 'end',
'data-mask')); ?>
</div>
And the Javascript that controls the inputs:
<script type="text/javascript">
$(function() {
$('input[name="start"]').daterangepicker({
timePicker24Hour: true,
singleDatePicker: true,
timePicker: false,
timePickerIncrement: 30,
locale: {
format: 'YYYY-MM-DD HH:mm:ss'
}
});
$('input[name="end"]').daterangepicker({
timePicker24Hour: true,
singleDatePicker: true,
timePicker: false,
timePickerIncrement: 30,
locale: {
format: 'YYYY-MM-DD HH:mm:ss'
}
});
});
</script>
The picker works just fine, it updates the field values properly, but when I attempt to save the form, the start field gets written to the database as follows:
start 0000-00-00 00:00:00
end (null)
The form data for the start and end fields saves properly if I'm reverting to the default configuration of the fields.
Any clue as to where I'm failing would be highly appreciated.
try something like this
$correctdate = date("Y-m-d j:h:m",strtotime($yourdate));
It's not a great peace of code, but it should help to go further in the right direction.
We take this string and make a timestamp out of it. Then we change it to a proper datetime value.
Okay, so I was passing text to a datetime field and the save operation failed. In order to fix this I had to convert the strings to the proper type by processing it in the beforeSave() function of the model.
Here is the code that worked for me:
public function beforeSave($options = array()) {
if (!empty($this->data['Task']['start']) && !empty($this->data['Task']['end'])) {
$this->data['Task']['start'] = $this->dateFormatBeforeSave($this->data['Task']['start']);
$this->data['Task']['end'] = $this->dateFormatBeforeSave($this->data['Task']['end']);
}
return true;
}
public function dateFormatBeforeSave($dateString) {
return date('Y-m-d h:m:s', strtotime($dateString));
}
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
});