Forums

DatePicker change Event

Rolfo 04 Nov, 2011
Hi Bob,

(My Joomla 1.7 system runs CF4.0 RC2.0 and the datepicker.js is version 1.17)
I use the Datepicker for a formfield to pick a date in 1 field, fill in a number of days in another field to then calculate the new date (on keyup) in the third field. That system works ok now by splitting the date, parsing, calculate and set the new value. (using field_clone_id.value)

Offcourse I want that function to run again when the date changes in the first field with the datepicker. I saw that you spoke about the 'onShowComplete' option but I cannot get that to work. I see an 'onclose' option in the datepicker.js but when I just fill in an alert there, the alert shows several times when even loading the page.

So my question is, is it possible to trigger my function (or paste my complete function in the JS file?) with this setup? And is upgrading to datepicker 2.1.1. as you wrote last month in this post http://chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=26&t=24670 profitable for achieving what I want?
GreyHead 04 Nov, 2011
Hi Rolfo,

If you are using the standard ChronoForms datapicker in CFv4 then there is no onShowComplete event. There is an onShow event - but that fires when the datepciker calendar pops up. I think you probably want the onSelect event that fires when a date is chose. That you'd use in the same way as any other datepicker option as an option setting probably in a Custom DatePicker element.

Bob
delacoux 04 Nov, 2011
I have a function I want to run when the date is changed on the form.
If I put another text field_name the javascript code works. If I put the date picker field_name it does not. Any idea why ?

window.addEvent('domready', function(){
$('date').addEvent('change', function(){

Thank you in advance.
Céline
GreyHead 05 Nov, 2011
Hi Céline,

This is probably because the datepicker hides the form input and replaces it with one of it's own. You can use the datepicker onSelect option to trigger your code instead.

Bob
Rolfo 05 Nov, 2011
Yes I found it on line 73 of the datepicker.js in com_chronoforms/js/ and I use the OnClose event.

For anyone who needs an 'onchange' datecalculation, this is my code:

[[>> Core removed by Greyhead - see the following post for the correct way to ise the OnClose option <<]]

Good luck!
GreyHead 06 Nov, 2011
Hi Rolfo,

There is absolutely no need to hack the code code to do this. The way it is set up is to enable you to defne a JavaScript function in a Load JavaScript action and call it by setting the function in the date picker options. In your case the function might be
function berekenvervaldatum() {
  if (document.getElementById('factuurdatum_clone_id').value != null 
      && document.getElementById('factuurdatum_clone_id').value != '' 
      && document.getElementById('betalingstermijn').value != null 
      && document.getElementById('betalingstermijn').value != ''){
    var factuurdatum = document.getElementById('factuurdatum_clone_id').value;
    factuurdatum = factuurdatum.split("-");
    factuurdatum = factuurdatum[2] +"-" +factuurdatum[1] +"-"+factuurdatum[0];
    factuurdatum = new Date(Date.parse(factuurdatum));
    var betalingstermijn = document.getElementById('betalingstermijn').value;
    var vervaldatum = factuurdatum;
    vervaldatum.setDate(factuurdatum.getDate() + parseInt(betalingstermijn));
    var vervaldag = vervaldatum.getDate(); if (vervaldag < 10){vervaldag="0"+vervaldag};
    var vervalmaand = vervaldatum.getMonth()+1; if (vervalmaand < 10){vervalmaand="0"+vervalmaand};
    var vervaljaar = vervaldatum.getFullYear();
    $('vervaldatum').set('value', vervaldag+"-"+vervalmaand+"-"+vervaljaar);
  } else {
    $('vervaldatum').set('value', '');
  }
}

and then in the datepicker options
onClose: berekenvervaldatum

Bob
This topic is locked and no more replies can be posted.