Buy Now
Sign in

DateTime Box

needshelp , April 04 2011, 17:00
E
emmexx 456
November 19 2012, 13:02 #302858
"GreyHead":

I've got this working with a chunk of custom code (needed because of some quirks in the way ChronoForms handles the datepickers).


Great! Thank you!!!

"GreyHead":

The form uses two standard Text box elements (not datepicker elements). They have ids 'start_date' and 'end_date'.
The Custom Code action has this code to load the required datepicker files (normally this is done by ChronoForms)


If I understand your code correctly, I used the following workaround: I added a Custom Datepicker in the OnLoad event. The CDTP is linked to nothing (a non-existent class).
That way CF loads all the needed files.

"GreyHead":

// add a check when the end datepicker is opened
end_date.addEvent('open', function() {
if ( start_date.date != end_date.date ) {
end_date.options.minDate = start_date.date;
}
});
});


I had used something similar probably with the wrong syntax.

Thank you
maxx
GreyHead 65
November 19 2012, 13:18 #302859
Hi Maxx,

Yes, adding a Custom DatePicker will also load the files. I just pulled the necessary chunks of code out of the file rather than add the whole action.

All this is only necessary because the ChronoForms code doesn't attach the datepickers to JavaScript variables so I can't see any way to access them directly.

Bob
If you'd like to buy me a coffee or two, thank you very much
E
emmexx 456
November 19 2012, 16:41 #302884
"GreyHead":

I've got this working with a chunk of custom code (needed because of some quirks in the way ChronoForms handles the datepickers). You can see it here


Sorry, I thought I saw your example working but I checked again and it is not what I need.

E.g. The form has 2 dates. The 2nd should be the same as the 1st one or empty.
If in the 1st I select 21 decembr 2013, I'd like to have 21 december 2013 as the default date when I open the DTP.
Your method blocks all dates before the one selected in the 1st DTP, but the DTP opens with today date. So I have to click many times to go to the right date.


// set up the end datepicker
end_date = new Picker.Date($('end_date'), {
pickerClass: 'datepicker_dashboard',
format: '%Y-%m-%d',
allowEmpty: true,
useFadeInOut: !Browser.ie
});
// add a check when the end datepicker is opened
end_date.addEvent('open', function() {
if ( start_date.date != end_date.date ) {
end_date.options.minDate = start_date.date;
}
});
});


I modified your code a little bit but the problem at the origin of my request for help came back.

  end_date.addEvent('open', function() 
{
if ( $('start_date').value != $('end_date').value ) {
end_date.select(Date.parse($('start_date').value));
}
});


When I click on the 2nd text box the DTP opens at the correct date. Then I select a time but the OK button on the timepicker is not responding. If I click on another element the DTP stays there. If I click again on the textbox the timepicker fades away, the datepicker appears and so on for an infinite loop.

bye
maxx
GreyHead 65
November 19 2012, 17:29 #302890
Hi Maxx,

Sorry, I misunderstood that.

Please try this in the if clause:
    if ( start_date.date != end_date.date ) {
end_date.select(start_date.date);
}


Or perhaps better:
    if ( start_date.date != end_date.date ) {
end_date.select(start_date.date);
end_date.options.minDate = start_date.date;
end_date.options.maxDate = start_date.date;
}

I updated the demo form to this version.
Bob
If you'd like to buy me a coffee or two, thank you very much
E
emmexx 456
November 19 2012, 17:46 #302892
"GreyHead":

I updated the demo form to this version.


Sorry Bob but your demo is not working for me. It could be browser dependent, I'm using firefox.
Clicking on the only date available on the DTP has no effect. The DTP stays open.

Anyway, I'll devise something else.

Thank you
maxx
GreyHead 65
November 19 2012, 17:52 #302893
Hi Maxx,

It's working OK here in FireFox, maybe the browser cache needs clearing.

Bob
Attachments
19-11-2012 18-51-14.png
19-11-2012 18-51-14.png
(14.45 KiB)
3408 Downloads/Views
If you'd like to buy me a coffee or two, thank you very much
E
emmexx 456
November 19 2012, 18:18 #302896
"GreyHead":

It's working OK here in FireFox, maybe the browser cache needs clearing.


Cache already cleared.

As you can see there are 2 DTPs because the end_date one is not closing after selecting a day.



bye
maxx
Attachments
dtp.png
dtp.png
(21.21 KiB)
3388 Downloads/Views
admin 33
November 21 2012, 15:08 #303002
There are no JS errors in the page ?

Did you try to add any "Custom date picker" actions to the form ?
E
emmexx 456
November 21 2012, 16:06 #303008
"admin":
There are no JS errors in the page ?


No js errors.

"admin":
Did you try to add any "Custom date picker" actions to the form ?


In my form there's a Custom date picker action but I don't use it directly, I create my own instances of the dtp.
But the images I attached refer to Bob's test page.
Anyway, Bob's code is not working on my laptop (firefox/linux). I didn't tested on other PCs.
But it works for Bob...

Thank you
maxx
Attachments
dtp1.png
dtp1.png
(32.82 KiB)
3364 Downloads/Views
GreyHead 65
November 21 2012, 18:06 #303015
Hi Maxx,

You are quite correct, sorry. The second datepicker doesn't close after you to select the date.

I can't immediately see a fix for that. There doesn't appear to be a method to set the date for the opening view other than the select() one that then jams the script.

Bob
If you'd like to buy me a coffee or two, thank you very much