Page 1 of 1

[SOLVED] How to implement calendars in a form??

Posted: Tue Oct 02, 2007 2:29 pm
by ghostrifle
Hi there,

I'm trying to use the calendar provided with joomla in the component. I'm using the following code to display the calendar:

Code: Select all

      <input class="inputbox" type="text" name="valid_from" id="valid_from" size="15" maxlength="10" value="<?php echo $this->rl_ad->valid_to; ?>" />
 <a href="#" onclick="return showCalendar('dates', 'y-mm-dd');"><img class="calendar" src="images/blank.png" alt="calendar" /></a>


In my view-object, I'm preparing the calendar with this code:

Code: Select all

function display($tpl = null)
   {
   ...
      
      JHTML::_('behavior.calendar'); // preparing the calendar
      $body_editor =& JFactory::getEditor();
      
      $this->assignRef( 'body_editor', $body_editor );
       $this->assignRef('rl_ad', $rl_ad);
       parent::display($tpl);
   }


Well the input field with the calendar displays... but when I wanna change the date by clickin on the icon... nothing happens.... so.. what am I doing wrong !??

Thanx, Alex

BTW: I'm using the current SVN

Re: How to implement calendars in a form??

Posted: Tue Oct 02, 2007 6:49 pm
by ghostrifle
The solution to my problem is quite easy:

remove all the code from above and replace with this code for displaying a date value with a popup calendar:

Code: Select all

<?php echo JHTML::_( 'calendar',$value,$name,$id); ?>


Have a look at this api doc for further information: http://api.joomla.org/svn/Joomla-Framework/HTML/JHTML.html#calendar

thanx to Ian MacLennan from J101 Chat

Re: [SOLVED] How to implement calendars in a form??

Posted: Sat Feb 09, 2008 1:58 pm
by aristondarmayuda
How about getting the value from calendar, I try to get the value by the name and the ID. For example I use calendar that called fdate then the name will be detail[fdate] and the ID is fdate.

Then I use code like this: $date = JRequest::getVar('detail[fdate]');

The code doesn't work? How to get the date???

Thanks,