My jquery UI datepicker is not showing week numbers, even with the showWeek:true option set. Here is my code:
<script type='text/javascript'>
$(document).ready(function(){
$('#startDate').datepicker({
changeMonth: true,
changeYear:true,
dateFormat: 'd-M-yy',
firstDay: 1,
showButtonPanel: true,
showWeek: true
});
});
</script>
<input type='text' name='startDate' id='startDate'>
From what I understand, you ONLY need to set the showWeek option to make this work - the weekHeading has a default of 'Wk' and the calculateWeekNumber has a built in ISO week number calculator function.
Also, for some reason the 'Today' button on the button panel is disabled?! Any advice would be most appreciated. Thanks.
I think you might be using jQueryUI v1.7.2.
You need v1.8 to get the showWeek option. I have v1.8rc3 and it works well.
demo:
http://jsbin.com/eliki
Related
I am using date range picker from http://tamble.github.io/jquery-ui-daterangepicker/
All I want is a drop down to select Month & Year.
I know there are options available to jQuery UI to render as a drop down instead of text for month and year.
However when I used that it applies only on first Datepicker only. I want drop down on both calender.
Below capture is form my demo on which I am working.
I found reference from here
var $datePicker = $("#TxtStrtDate,#TxtExpDte");
$datePicker.datepicker({
changeMonth: true,
changeYear: true,
inline: true,
altField: "#datep",
}).change(function(e){
setTimeout(function(){
console.log(e, e.currentTarget, $datePicker.find('.ui-datepicker-current-day:visible')[0]);
$datePicker
.find('.ui-datepicker-current-day')
.next('td')
.children('.ui-state-default')
.addClass('ui-state-active');
});
});
Fiddle
I am using jquery date picker with cakephp 2.3. Datepicker popup is OK.
When I want to edit a any record, it does not display date field value in form. I checked many ways and I am sure that it is date picker issue.
Populated source code of date field
<input id="CallDateTo" class="hasDatepicker" type="text" value="2013-04-15" name="data[Call][date_to]">
Here we see that value exist in HTML but it does not display in form.
Any one can help me?
Yes, I found the solution. I have to write as bellow
$( "#CallDateFrom, #CallDateTo" ).datepicker({ dateFormat: "yy-mm-dd"});
Before that I wrote as bellow and caused the problems.
$( "#CallDateFrom, #CallDateTo" ).datepicker({ changeMonth: true, changeYear: true});
$( "#CallDateFrom, #CallDateTo" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );
Set the date using correct format
$('#CallDateTo').datepicker({
dateFormat: "yy-mm-dd"
});
Demo: Plunker
When I load my page the datepicker on my div always show in english, I have to click it to show in other language, as you can see in this fiddle: http://jsfiddle.net/bFHxf/
If you change from div to input there is no problem with it since you have to click it to show... is this some kind of feature or bug?
Any workaround?
I wrapped your code in the $(document).ready() function and that seems to take care of the problem.
http://jsfiddle.net/qtNyr/
Hope that helps!
I think that you are initializing the datepicker too early.
If you wait until the document is loaded, it should work. You can do this by surrounding the existing JavaScript code with
$(function() { existing code goes here });
So the result might look like:
$(function(){
$.datepicker.setDefaults( $.datepicker.regional[ "nl" ] );
$('#date').datepicker({
numberOfMonths: 2,
showButtonPanel: true,
dateFormat : 'dd/mm/yy'
});
})
Link to jsFiddle
I have a very simple html page with the following javascript in it
$(function() {
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true
});
$( "#datepicker" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
});
Then I have the input target element
<input id="datepicker" type="text" class="boxtpl" name="${field.name}" value="${release?.startDate}">
and I see the html of the input from viewing source is valid...
<input id="datepicker" type="text" class="boxtpl" name="release.startDate" value="2012-02-07">
so when I do the GET request to get this page, my date ONLY renders if I delete that last line in the javascript that sets the format WHICH is very important as that is the format I have playframework configured for!!!!! If I don't set the format, the POST then breaks because formats don't match :(
Why is setting the format of datepicker clearing out my date????
I can try scripting more to set it manually though I tried calling the api to set it and that DID NOT work so it might not work doing raw javascript set either...not sure yet. anyone know why this occurs or better yet how to fix it???
thanks,
Dean
Not sure if it's a bug in jquery ui, but it seems that setting the format effectively deletes the default value. You can fix this with a chained
.datepicker("setDate", datepicker_default_val );
However, what I did in my web app was define a CSS class ".datepicker" then writing this code snippet provide date pickers to any with that class.
$( ".datepicker" ).each( function(index){
var datepicker_default_val = $(this).val();
$( this ).datepicker({numberOfMonths: 3, showButtonPanel: true});
$( this ).datepicker( "option", "dateFormat", 'yy-mm-dd' );
$( this ).datepicker("setDate", datepicker_default_val );
});
What this does is grabs every element with the tagged class, saves the default value to local var datepicker_default_val, sets the formatting, and then restores the value.
Little bit of a hack but put that in a $(document).ready(function(){ }); block and you should be good.
If the input field does not match the default dateFormat, it will simply delete it.
The option setting in the second line is too late then, after the first line it is already deleted.
Solution: Set the dateFormat in the first call:
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd"
});
What do you mean by:
the POST then breaks because formats don't match
Also, I don't quite understand what you mean by your GET and POST requests? Do you mean the form methods? In such case you should amend your HTML code with the surrounding form tags and add a submit button so we can understand exactly what you want and try to reproduce the problem.
Anyway, see if this is what you want : http://jsfiddle.net/DAMEj/
Actually I just included the Jquery UI library in addition to their CSS for a full test of your code.
Besides, I don't get the purpose of these attributes name="${field.name}" value="${release?.startDate}", could you clarify?
And finally, what is it exactly that doesn't work for you?
EDIT:
So according to my last comment about the default date display, please check this out http://jsfiddle.net/sidou/ZUrPj/ and see if it fits your needs.
Happy JS fiddling ;)
If the input value is not parseable by jQuery, it will indeed delete the value from the input field (and even from the altField, if you set one).
For example, this might happen when using different locales. If you set the datepicker dateFormat to 'dd MM yy' and use French localisation, it will parse "10 Mars 2012", however a value of "10 March 2012" will get deleted.
In my case, i found than the JQuery was inyected by a "formoid" solution, soo, i just replace the function where the data was reinjected, adding the line
"value": date.attr("value")
I mixed with the Shaun answer too:
jQuery(".formoid-flat-blue").find('input[type=date]').each(function(){
var date = $(this);
var datepicker_default_val = $(this).val();
var text = $('<input type="text">');
text.get(0).className = date.get(0).className;
text.attr({
"name": date.attr("name"),
"placeholder": date.attr("placeholder"),
"required": date.attr("required"),
"value": date.attr("value")
});
date.replaceWith(text);
text.datepicker({
format: _dateFormat || date.attr("data-format") || 'yyyy-mm-dd'
});
if (datepicker_default_val) {
text.datepicker({
setDate: datepicker_default_val
});
}
});
<script>
$('#end_time').ready(function(){
$('#end_time').datepicker({
altFormat: "yy-mm-dd h:i:s",
changeYear: true,
changeMonth: true,
dateFormat: "yy-mm-dd h:i:s",
yearRange: "2011:2020"
});
});
</script>
=> output: 2011-06-30 h:i:s
I want output is: 2011-06-30 15:14:21
Who can help me ?
CMIIW, datepicker is only to pick date. time (hour,minute,second) is not included.
so the formatting for time is not there.
use this one that extend jquery ui datepicker. you can pick up both date and time.
http://trentrichardson.com/examples/timepicker/
a datepicker is for picking a DATE
there is no time component available via datepicker.
if you want to use the current time or any other time, you can write your own functions for parsing the date (without the time, so that datepicker still works) and for appending the time after picking a date