Forums

How to create custom validation for comparing date & time

moleculezz 18 May, 2010
Hello,

I have been creating a somewhat complex form. What it does is allows a user to book one way or retour pickup service. Depending on a radio button it colapses extra information for the retour.
The user has to select the date & time for pickup (1 calendar input, 1 hour select, 1 minutes select) and also the same for the return trip if selected. This is all working, but now I have some issues with validating or restricting the return date & time to atleast 1 hour after the date & time for the pickup.

I know the calendar supports mutli-calendar support with padding, but it doesn't seem that I can use it. It requires a nested calendar variable and chronoforms does not do this. If I could use this it would solve my date difference problem, but I still have to find a way to deal with the time difference problem.

I would like to ask for some guidance or direction to where I should look for a solution for this. Is there a way to create my own custom validation or extended validation to deal with this problem?
If so, can anyone point me in the right direction?
GreyHead 18 May, 2010
Hi moleculezz,

What is a 'nested calendar variable'?

You can create linked calendars with the Aeron calendar - but it has no time-picker :-(

Bob
moleculezz 18 May, 2010

What is a 'nested calendar variable'?



On the site of the developer it is shown that, to use the multi-calendar, one needs to use the following syntax

myCal = new Calendar({
  day1: { monthyear1: 'Y-m', day1: 'd' },
  day2: { monthyear2: 'Y-m', day2: 'd' }
}, { pad: 2 });


But in chronoforms you get the following two separate variables

myCal_datum = new Calendar({ datum: 'd/m/Y' }, { classes: ['dashboard'], direction: .5 });
myCal_datum_retour = new Calendar({ datum_retour: 'd/m/Y' }, { classes: ['dashboard'], direction: .5 });


You can create linked calendars with the Aeron calendar - but it has no time-picker :-(



How can I create linked calendars with the Aeron calendar in chronoforms?
I have not been able to get this working.
If I can get this working I might be able to figure out a way to deal with the time difference.
moleculezz 21 May, 2010
Hi,
I tried the code from the post. But it's not working. It does something really weird to the backend of chronoforms. It messes up the whole tabs. It displays all tabs in one page under each other.
This happens when I put the php code on top of the html code. Only when I remove the php code it shows the backend like it's suppose to.

<?php
$script = "new Calendar( {datum: 'd/m/Y', datum_retour: 'd/m/Y'}, {direction: .5, pad: .5, classes: ['dashboard']} );";

jimport('joomla.environment.browser'); 
$browser = JBrowser::getInstance();

if ( $browser->getBrowser() == 'msie' ) {
	$loader = 'load';
} else { 
	$loader = 'domready';
}

$doc =& JFactory::getDocument();
$script = "window.addEvent('".$loader."', function() { ".$script." });";
$doc->addScriptDeclaration($script);
?>
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Datum rit<span class="star"> *</span></label>
    <input class="cf_inputbox" title="Vul hier de datum van uw rit in!" size="" id="datum" name="datum" type="text" />
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Datum rit <span class="star">*</span></label>
    <input class="cf_inputbox" title="Vul hier de datum van uw retourrit in!" size="" id="datum_retour" name="datum_retour" type="text" />
    
  </div>
  <div class="cfclear"> </div>
</div>
GreyHead 21 May, 2010
Hi moleculezz,

The current version of ChronoForms has a *feature* that causes this. Add this line before any PHP that you put in the Form HTML box.
<?php
if ( !$mainframe->isSite() ) { return; }
. . .

This stops the PHP being executed in the site Admin.

Bob
moleculezz 25 May, 2010

<?php
if ( !$mainframe->isSite() ) { return; }
?>



Hi again,

Ok, so now the backend behaves like it should. But the calendars aren't working at all. An error pops up in Firebug.
Calendar is not defined


I do want to point out that I removed all names from the "Date Fields Settings" on the "General" tab.
GreyHead 25 May, 2010
Hi moleculezz,

I'd guess that the calendar script files aren't being loaded then. I think that they are included in the ChronoForms js/css files.

Bob
moleculezz 25 May, 2010
Hey Bob,
I did an experiment. It turns out that the calendar script files are loaded when there is at least one "Date Fields name" in the "Date Fields Settings" area.

What can I do to load the scripts?
GreyHead 25 May, 2010
Hi moleculezz,

Include them from the Form HTML.

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