Development

#458 ([Patch] Added the possibility to send html options to the input_date_tag)

You must first sign up to be able to contribute.

Ticket #458 (closed enhancement: fixed)

Opened 3 years ago

Last modified 2 years ago

[Patch] Added the possibility to send html options to the input_date_tag

Reported by: chris@enchr.com Assigned to:
Priority: minor Milestone:
Component: Version: 0.7.X
Keywords: Cc:
Qualification:

Description

Hi,

I made modifications in the input_date_tage (from the FormHelper?) to be able to send html options.

Here is the modified file :

/**
 * My Input_date_tag Hack
 * 
 * - Add possibility to send HTML option to input Tag
 * 
 */
 
// Hack CGB - 24/04/2006 - replaced
//function MyInput_date_tag($name, $value, $options = array())
function MyInput_date_tag($name, $value, $options = array(), $htmlOptions = array())
{
  $options      = _parse_attributes($options);
  $htmlOptions  = _parse_attributes($htmlOptions);                                        // Hack CGB - 24/04/2006 - Added

  $context = sfContext::getInstance();
  if (isset($options['culture']))
  {
    $culture = $options['culture'];
    unset($options['culture']);
  }
  else
  {
    $culture = $context->getUser()->getCulture();
  }

  // rich control?
  $rich = false;
  if (isset($options['rich']))
  {
    $rich = $options['rich'];
    unset($options['rich']);
  }

  if (!$rich)
  {
    throw new sfException('input_date_tag (rich=off) is not yet implemented');
  }

  // parse date
  if (($value !== null) && ($value != '') && (!is_int($value)))
  {
    $value = strtotime($value);
    if ($value === -1)
    {
      $value = 0;
//      throw new Exception("Unable to parse value of date as date/time value");
    }
    else
    {
      $dateFormat = new sfDateFormat($culture);
      $value = $dateFormat->format($value, 'd');
    }
  }

  // register our javascripts and stylesheets
  $langFile = '/sf/js/calendar/lang/calendar-'.strtolower(substr($culture, 0, 2));
  $jss = array(
    '/sf/js/calendar/calendar',
    is_readable(sfConfig::get('sf_symfony_data_dir').'/web/'.$langFile.'.js') ? $langFile : '/sf/js/calendar/lang/calendar-en',
    '/sf/js/calendar/calendar-setup',
  );
  foreach ($jss as $js)
  {
    $context->getResponse()->addJavascript($js);
  }
  $context->getResponse()->addStylesheet('/sf/js/calendar/skins/aqua/theme');

  // date format
  $dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture);
  $date_format = strtolower($dateFormatInfo->getShortDatePattern());

  // calendar date format
  $calendar_date_format = $date_format;
  $calendar_date_format = strtr($calendar_date_format, array('M' => 'm', 'y' => 'Y'));
  $calendar_date_format = preg_replace('/([mdy])+/i', '%\\1', $calendar_date_format);

  $js = '
    document.getElementById("trigger_'.$name.'").disabled = false;
    Calendar.setup({
      inputField : "'.$name.'",
      ifFormat : "'.$calendar_date_format.'",
      button : "trigger_'.$name.'"
    });
  ';

  // construct html
  // Hack CGB - 24/04/2006 - replaced
  // $html = input_tag($name, $value);
  $html = input_tag($name, $value, $htmlOptions);                                                           

  // calendar button
  $calendar_button = '...';
  $calendar_button_type = 'txt';
  if (isset($options['calendar_button_img']))
  {
    $calendar_button = $options['calendar_button_img'];
    $calendar_button_type = 'img';
    unset($options['calendar_button']);
  }
  else if (isset($options['calendar_button_txt']))
  {
    $calendar_button = $options['calendar_button_txt'];
    $calendar_button_type = 'txt';
    unset($options['calendar_button']);
  }

  if ($calendar_button_type == 'img')
  {
    $html .= image_tag($calendar_button, array('id' => 'trigger_'.$name, 'style' => 'cursor: pointer', 'align' => 'absmiddle'));
  }
  else
  {
    $html .= content_tag('button', $calendar_button, array('disabled' => 'disabled', 'onclick' => 'return false', 'id' => 'trigger_'.$name));
  }

  if (isset($options['with_format']))
  {
    $html .= '('.$date_format.')';
    unset($options['with_format']);
  }

  // add javascript
  $html .= content_tag('script', $js, array('type' => 'text/javascript'));

  return $html;
}

Hope it will be append to the next release.

Regards

Christophe

Attachments

myFormHelper.php (3.6 kB) - added by chris@enchr.com on 04/24/06 13:51:53.
Hack for the input_date_tag function

Change History

04/24/06 13:51:53 changed by chris@enchr.com

  • attachment myFormHelper.php added.

Hack for the input_date_tag function

04/25/06 13:00:41 changed by nospam@kinokai.de

  • summary changed from Added the possibility to send html options to the input_date_tag to [Patch] Added the possibility to send html options to the input_date_tag.

05/07/06 18:50:31 changed by l2k <symfony-trac@cny.de>

  • status changed from new to closed.
  • resolution set to fixed.

fixed in r1244

right?

02/18/07 09:44:07 changed by fabien

(In [3489]) allow symlinked test files (closes #458 - patch from trivoallan)