View Full Version : DatePicker
Jink
21 Jul 2007, 12:45 PM
I have a form with a DateField and a DeatePicker. To that lets say I have an array:
var a = new Array(['11/07/07'],['12/07/07'],['13/07/07']);
How can I provide th
brian.moeskau
21 Jul 2007, 3:44 PM
Are you asking how to format the JSON data so that you can initialize the DateField dynamically, or are you asking how to change the disabled days for an already existing DateField?
vtswingkid
25 Jul 2007, 8:11 AM
Does this work for 1.1?
I set disableDates: ["07/07", "07/08"].
Yet nothing is disabled.
brian.moeskau
25 Jul 2007, 8:31 AM
Currently, no that will not work. DateField should probably have a setter function to allow you to do this as the calendar must be re-rendered in order to reflect the new disabled dates, and simply changing the config property won't do that.
Here's a workaround I whipped up for now:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test Page</title>
<script type="text/javascript" src="../_src/1.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../_src/1.1/ext-all-debug.js"></script>
<link rel="stylesheet" type="text/css" href="../_src/1.0/resources/css/ext-all.css">
<script>
Ext.onReady(function(){
Ext.override(Ext.form.DateField, {
setDisabledDates: function(dd){
var re = "(?:";
for(var i = 0; i < dd.length; i++){
re += dd[i];
if(i != dd.length-1) re += "|";
}
this.ddMatch = new RegExp(re + ")");
this.menu.picker.update(this.menu.picker.activeDate.add('mo',-1));
}
});
var df = new Ext.form.DateField({
fieldLabel: 'Arrival',
name: 'arrival',
format: 'd/m/y',
width:190,
allowBlank:false,
disabledDates : ['07/07/07','03/07/07' ],
disabledDatesText: "This date is allready full booked",
renderTo: 'dt'
});
Ext.fly('disableBtn').on('click', function(){
df.setDisabledDates(['10/07/07','11/07/07', '13/07/07']);
})
});
</script>
</head>
<body>
<div id="dt"></div>
<br />
<input id="disableBtn" type="button" value="Change disabled dates" />
</body>
</html>
This adds a new method setDisabledDates to the DateField which takes an array of dates as expected. This is a pretty ugly hack for two reasons. First, the regex logic is duplicated directly from the constructor of DateField, but since it's inline in the constructor currently, there's no way to reuse it. Ideally, the constructor would call this function instead. Secondly, that last line in the override probably looks a little strange. You have to tell the picker to update itself, but it currently has logic that if you're already on the current date, it exits without actually updating. This tells it to change months, forcing it to re-render internally.
So this should work for you for now, but we'll see about making a few changes to DateField so that it supports this correctly.
tryanDLS
25 Jul 2007, 8:44 AM
I just tested this in the edit grid example and it works correctly (1.1RC1).
editor: new Ed(new fm.DateField({
format: 'm/d/y',
minValue: '01/01/06',
disabledDays: [0, 6],
disabledDates:['07/25', '07/26'],
disabledDaysText: 'Plants are not available on the weekends'
}))
brian.moeskau
25 Jul 2007, 8:55 AM
Can you change the disabledDates after it's been set? There doesn't seem to be a way to do that.
vtswingkid
25 Jul 2007, 9:09 AM
Thanks for the code. I was actually using mine inside a form and the datefield gets rebuilt everytime it is triggered. This is sufficient for my current usage.
Your working code helped me deduce, that the array of dates must match the specified format. That is why my code was failiing. Hope this helps someone in my shoes.
I do like the idea of a setDisabledDates function.
Found out, it all worked - the problem was that i forgot to change out so I used a HttpProxy when reading from the data with JSON, so thats somehow solved now, so now it reads the disableddates from the JSON reader :)
I have a DatePicker set with som DisabledDates, and the dates can change based on what the user selects. The way I do it is that i simply destroy the old datepicker and then creating a new one, with the new all new dates from the JSON reader.
Keep in mind that my datepicker here is shown all the time, so i couldn't find any way to "refresh" it with the new data, without having to destroy the old DatePicker first. Maybe i can do it without having to destroy it?
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.