API15

API15:JHTML/calendar

From Joomla! Documentation

Revision as of 22:18, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Displays a calendar control field <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Displays a calendar control field

[Edit Descripton]

Template:Description:JHTML/calendar

Syntax

calendar($value, $name, $id, $format= '%Y-%m-%d', $attribs=null)
Parameter Name Default Value Description
$value The date value
$name The name of the text field
$id The id of the text field
$format '%Y-%m-%d' The date format
$attribs null Additional html attributes

Defined in

libraries/joomla/html/html.php

Importing

jimport( 'joomla.html.html' );

Source Body

function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = null)
{
        JHTML::_('behavior.calendar'); //load the calendar behavior

        if (is_array($attribs)) {
                $attribs = JArrayHelper::toString( $attribs );
        }
        $document =& JFactory::getDocument();
        $document->addScriptDeclaration('window.addEvent(\'domready\', function() {Calendar.setup({
inputField     :    "'.$id.'",     // id of the input field
ifFormat       :    "'.$format.'",      // format of the input field
button         :    "'.$id.'_img",  // trigger for the calendar (button ID)
align          :    "Tl",           // alignment (defaults to "Bl")
singleClick    :    true
});});');

        return '<input type="text" name="'.$name.'" id="'.$id.'" value="'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'" '.$attribs.' />'.
                         '<img class="calendar" src="'.JURI::root(true).'/templates/system/images/calendar.png" alt="calendar" id="'.$id.'_img" />';
}

[Edit See Also] Template:SeeAlso:JHTML/calendar

Examples

<CodeExamplesForm />