Forums

Multiple datepicker instances

someguy2k 05 Feb, 2011
I am using the following code to loop through a record-set and dynamically create a form with different form_element/cf_form fields. The form is able to build the dynamic cf_fields, email and submit data.

The problem I am having is with the the calendar. I only see the input field and not the calendar. So the dates are manually being entered.

Is it possible to have more than 1 datetimepicker instance?

$i=1;
while (!empty($options['0'][$task]))
 {
$cdate = "completedate_" . $i;
....
echo "<div class='form_item'><div align='center'><div class='form_element cf_datetimepicker'><input class='cf_datetime' title='' size='8' id='".$cdate."' name='".$cdate."' type='text' /></div><div class='cfclear'></div></div></div></td>";
$i++;
}

As it stands, I am only able to display 1 cf_datetimepicker with input and calendar. Any ideas? -
GreyHead 05 Feb, 2011
Hi someguy2k,

ChronoForms uses the list of datapicker names in the Form General tab to loop through and set up the calendars. With this approach that list can't be complete. I haven't tested it but I think this will do what is needed (you may then need to clear the name list to stop a duplication).
$i=1;
while (!empty($options['0'][$task]))
{
  $cdate = "completedate_" . $i;
  ....
  echo "<div class='form_item'><div align='center'><div class='form_element cf_datetimepicker'> <input class='cf_datetime' title='' size='8' id='$cdate' name='$cdate' type='text' /></div><div class='cfclear'></div></div></div></td>";
  HTML_ChronoContact::initiateCalendar($cdate, $MyForm);
  $i++;
}

Bob
someguy2k 05 Feb, 2011
Bob - Thank You for the quick reply

I get the following output when I add HTML_ChronoContact::initiateCalendar($cdate, $MyForm);

i'm using
echo "<div class='form_item'><div align='center'><div class='form_element cf_datetimepicker'> <input class='cf_datetime' title='' size='8' id='$cdate' name='$cdate' type='text' /></div><div class='cfclear'></div></div></div></td>";
HTML_ChronoContact::initiateCalendar($cdate, $MyForm);
GreyHead 05 Feb, 2011
Hi someguy2k,

OK - looks as though I have to dig a bit further. Somewhere it needs to be wrapped in script tags.

Back in a while.

Bob
GreyHead 06 Feb, 2011
Hi someguy2k,

Trying again
$i=1;
$script = "";
$datefieldformat =& $MyForm->formparams('datefieldformat', 'd/m/Y');
$datefieldextras =& $MyForm->formparams('datefieldextras', "classes: ['dashboard']");
while (!empty($options['0'][$task]))
{
  $cdate = "completedate_" . $i;
  ....
  echo "<div class='form_item'><div align='center'><div class='form_element cf_datetimepicker'> <input class='cf_datetime' title='' size='8' id='$cdate' name='$cdate' type='text' /></div><div class='cfclear'></div></div></div></td>";
  $script .= "myCal_$cdate = new Calendar({ $cdate: '$datefieldformat' }, { $datefieldextras });";
  $i++;
}
if ( $script ) {
  $doc =& JFactory::getDocument();
  $script = "window.addEvent('domready', function() { $script });";
  $doc->addScriptDeclaration($script);
}

This now includes the code from the initiateCalendar method and loads it as a script into the page header.

Bob
someguy2k 06 Feb, 2011
That fixed the output problem. I'm back to the datepicker field only showing the input box. The idea was to make it easier for the user, allowing them to pick a calendar-date rather than typing it.
GreyHead 06 Feb, 2011
Hi someguy2k,

Missed that bit. Do you have "Load Chronoforms CSS/JS Files?" set to 'Yes' in the Form general tab?

Bob
someguy2k 07 Feb, 2011
Your solution worked, Load Chronoforms CSS/JS Files was turned. I couldn't see it at 1st because I had the form loading inside my Tabs Module, which I can work around.

I have two additional questions.

1. How do I buy you a bear
2. Does the chronoform cookbook discuss advanced topics like this.

Thank you for you help!
GreyHead 08 Feb, 2011
Hi someguy2k,

You can buy me a beer through the link in my sig below. Thanks for the thought.

The books discussed some advanced features like this - though not this one. There isn't a great deal on handling dates. There are only 350 pages and not everything made it into the final version :-(

Bob
someguy2k 10 Feb, 2011
Can this be done to load dynamic fileupload fields? I used $file:jpg|png|pdf|xls{9999-1} and that didn't work...
$file = "fileupload_" . $i;
....

echo "<td height='30'><div align='center'><div class='form_item'><div class='form_element cf_fileupload'>";$me = $options['0'][$file];
	if (empty($me)) {
	echo "<input class='cf_fileupload ' title='' size='10' id='$file' name='$file' type='file' />";
GreyHead 10 Feb, 2011
Hi someguy2k ,

Basically . . . No. That input just takes a text string. I think that you'd need to hand-code the file uploading do do this.

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