/**
  * @param  string $name        The element name
  * @param  string $value       The date displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $url = url_for('@pm_widget_form_propel_input_by_code', true);
     $options_without_template = $this->getOptions();
     unset($options_without_template['template']);
     return parent::render($name, $value, $attributes, $errors) . sprintf($this->getOption('template'), $this->generateId($name . '_result'), $this->generateId($name), $url, serialize($options_without_template));
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (is_array($value)) {
         $values = array($value['postcode'], $value['city'], $value['address']);
     } elseif ($value) {
         $values = explode('|', $value);
     } elseif (!$value) {
         $values = array('', '', '');
     }
     $sfWidget = new sfWidgetFormInputText();
     $postcode = $sfWidget->render($name . '[postcode]', $values[0], array('maxlength' => 5, 'style' => 'width:50px'));
     $city = $sfWidget->render($name . '[city]', $values[1], array('style' => 'width:100px'));
     $address = $sfWidget->render($name . '[address]', $values[2], array('style' => 'width:200px'));
     $res = str_replace(array('%postcode%', '%city%', '%address%'), array($postcode, $city, $address), $this->getOption('iformat'));
     return $res;
     // parent::render($name, $value, $attributes, $errors);
 }
 /**
  * @param  string $name        The element name
  * @param  string $value       The value displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (is_array($attributes['data-options'])) {
         $attributes['data-options'] = json_encode($attributes['data-options']);
     }
     $response = sfContext::getInstance()->getResponse();
     $response->addStylesheet('/jfPortableDeviceExtFormsPlugin/datebox/jquery.mobile.datebox.css', 'last');
     $response->addJavascript('/jfPortableDeviceExtFormsPlugin/datebox/jquery.mobile.datebox.min.js', 'last');
     return parent::render($name, $value, $attributes, $errors);
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $colorAttributes = array('style' => 'background-color:' . $value, 'id' => 'preview_' . $name, 'class' => 'color');
     $result = $this->renderContentTag('dd', parent::render($name, $value, $attributes, $errors));
     $i18n = sfContext::getInstance()->getI18N();
     if ($this->getOption('is_display_pre_color')) {
         $result .= $this->renderContentTag('dd', $this->renderContentTag('div', $i18n->__($this->getOption('pre_color_label'))), array_merge($colorAttributes, array('id' => 'preview_pre_' . $name)));
     }
     $result .= $this->renderContentTag('dd', $this->renderContentTag('div', $i18n->__($this->getOption('color_label'))), $colorAttributes);
     return $result;
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $select_parent = parent::render($name, $value, $attributes, $errors);
     //$foreing_id = $this->getOption('foreing_id') ? $this->getOption('foreing_id') : strtolower($this->getOption('model').'_id');
     $option_name = $this->getOption('option_name') ? $this->getOption('option_name') : 'widget-time';
     //$where = $this->getOption('where') ? ' where="'.$this->getOption('where').'"' : '';
     $conten_tag = '<div>';
     $conten_tag .= $select_parent;
     $conten_tag .= '<input type=#text" class="input_text" name="' . $option_name . '" />';
     $conten_tag .= '</div>';
     return $conten_tag;
 }
 /**
  * Renders the widget.
  *
  * @param  string $name        The element name
  * @param  string $value       The value displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $widget = parent::render($name, $value, $attributes, $errors);
     $class = '';
     if ($this->getOption('prepend_text')) {
         $widget = sprintf('<span class="add-on">%s</span>%s', $this->getOption('prepend_text'), $widget);
         $class .= 'input-prepend';
     }
     if ($this->getOption('append_text')) {
         $widget = sprintf('%s<span class="add-on">%s</span>', $widget, $this->getOption('append_text'));
         $class .= ' input-append';
     }
     if ($class) {
         $widget = sprintf('<div class="text-%s %s">%s</div>', $this->generateId($name), trim($class), $widget);
     }
     return $widget;
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $values = array_merge(array('text' => '', 'is_empty' => false), is_array($value) ? $value : array());
     $divname = $this->getOption('divname');
     $obj_name = $this->getName($value);
     $obj_id = $this->generateId($name) . "_name";
     $input = parent::render($name, $value, $attributes, $errors);
     $attributes = array_merge($attributes, array('id' => $obj_id, 'class' => 'large_size'));
     $input .= parent::render('', $obj_name, $attributes, $errors);
     if ($this->getOption('nullable')) {
         $options = array('src' => '/images/remove.png', 'class' => $divname . '_reference_clear');
         if ($obj_name == '') {
             $options['class'] .= ' hidden';
         }
         $input .= $this->renderTag('img', $options);
     }
     $script_header = '<script type="text/javascript"> $(document).ready(function () {';
     $script_footer = '});</script>';
     $script_formated = sprintf('jQuery("#%1$s").focus(function() 
                                 {
                                   if (jQuery("div.%2$ssearch_box:hidden").length)
                                   {
                                     jQuery("div.%2$ssearch_box, ul.tab_choice").slideDown();
                                   }
                                   jQuery("div.%2$ssearch_box table#search_and_choose tbody td:first input:first").focus();
                                 });
                                 
                                 $(".%2$sreference_clear").click(function()
                                 {
                                   $(this).prevAll("input").val("");
                                   $(this).hide();
                                 });
                                ', $obj_id, $divname);
     foreach ($this->getOption('fieldsHidders') as $key => $value) {
         $script_formated .= sprintf('jQuery("#%1$s").focus(function() 
                                    {
                                      if (jQuery("div.%2$ssearch_box:visible").length)
                                      {
                                        jQuery("div.%2$ssearch_box, ul.tab_choice").slideUp();
                                      }
                                    });
                                   ', $value, $divname);
     }
     return $input . $script_header . $script_formated . $script_footer;
 }
    /**
     * Renders the widget.
     *
     * @param  string $name        The element name
     * @param  string $value       The value displayed in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        if (!$this->getAttribute('size')) {
            $this->setAttribute('size', $this->getOption('with_time') ? 15 : 9);
        }
        $this->default_picker_options['timeFormat'] = $this->getOption('time_format');
        $this->default_picker_options['dateFormat'] = $this->getOption('date_format');
        $this->default_picker_options['showSecond'] = strstr($this->getOption('time_format'), 'ss') !== false;
        if ($timestamp = strtotime($value)) {
            $value = strtr($this->getOption('date_format'), array('yy' => date('Y', $timestamp), 'mm' => date('m', $timestamp), 'dd' => date('d', $timestamp), 'y' => date('y', $timestamp), 'm' => date('n', $timestamp), 'd' => date('j', $timestamp)));
            if ($this->getOption('with_time')) {
                $value .= ' ' . strtr($this->getOption('time_format'), array('hh' => date('H', $timestamp), 'mm' => date('i', $timestamp), 'ss' => date('s', $timestamp), 'h' => date('G', $timestamp), 'm' => intval(date('i', $timestamp)), 's' => intval(date('s', $timestamp))));
            }
        }
        // Generate the datePicker javascript code
        $jq_picker_options = array_merge($this->default_picker_options, $this->getOption('jq_picker_options'));
        if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
            $jq_picker_options = json_encode($jq_picker_options, JSON_FORCE_OBJECT);
        } else {
            $jq_picker_options = json_encode($jq_picker_options);
        }
        $jq_picker_options = str_replace('\\/', '/', $jq_picker_options);
        // Fix for: http://bugs.php.net/bug.php?id=49366
        $pickerClass = $this->getOption('with_time') ? 'datetimepicker' : 'datepicker';
        $id = $this->generateId($name);
        $attributes['class'] = 'sfDateTimePicker' . (isset($attributes['class']) ? ' ' . $attributes['class'] : '');
        $html = parent::render($name, $value, $attributes, $errors);
        foreach ($this->getStylesheets() as $file => $options) {
            $html .= stylesheet_tag($file, $options);
        }
        foreach ($this->getJavaScripts() as $file) {
            $html .= javascript_include_tag($file);
        }
        $html .= <<<EOHTML

<script type="text/javascript">
  jQueryPicker(function(){
    jQueryPicker("#{$id}").{$pickerClass}({$jq_picker_options});
//    jQueryPicker(".ui-datepicker").draggable();
  });
</script>

EOHTML;
        return $html;
    }
 /**
  * Render field
  * 
  * @param   string  $name       Element name
  * @param   string  $value      Field value [optional]
  * @param   array   $attributes HTML attributes [optional]
  * @param   array   $errors     Field errors [optional]
  * @return  string  XHTML compliant tag
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (!is_array($value)) {
         $value = (string) $value == (string) (int) $value ? (int) $value : strtotime($value);
         if (false === $value) {
             $value = '';
         } else {
             $value = array('year' => date('Y', $value), 'month' => date('m', $value), 'day' => date('d', $value));
         }
     }
     $dateValue = '';
     if (is_array($value)) {
         $value = array_merge(array('year' => null, 'month' => null, 'day' => null), $value);
         $dateValue = strtr($this->getOption('format'), array('%month%' => $value['month'], '%year%' => $value['year'], '%day%' => $value['day']));
     }
     $widget = new sfWidgetFormInputText(array(), $attributes);
     return $widget->render($name, $dateValue) . '<script type="text/javascript">if(typeof jQuery!=\'undefined\'){$(function(){$("#' . $widget->generateId($name, $dateValue) . '").datepicker(' . ($this->getOption('config') ? '{' . $this->getOption('config') . '}' : '') . ');});' . ($this->getOption('lang') ? '$("#' . $widget->generateId($name, $dateValue) . '").datepicker($.datepicker.regional[\'' . $this->getOption('lang') . '\']);' : '') . '}</script>';
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $i18n = dmContext::getInstance()->getServiceContainer()->getService('i18n');
     $page = '';
     if ($value) {
         try {
             $page = DmPageTable::getInstance()->findOneById($value);
             $page = $page->getTitle();
         } catch (Exception $e) {
             $page = $i18n->__('ERROR: This page does not exist anymore.');
         }
     }
     $data = array('page' => $page, 'title' => $i18n->__('Drag & Drop page from PAGE bar.'), 'clear_page_message' => $i18n->__('Clear page'), 'goto_page_message' => $i18n->__('Open page'));
     if (isset($attributes['class'])) {
         $attributes['class'] .= ' sfWidgetFormDmPageLink ' . str_replace('"', "'", json_encode($data));
     } else {
         $attributes['class'] = 'sfWidgetFormDmPageLink ' . str_replace('"', "'", json_encode($data));
     }
     return parent::render($name, $value, $attributes, $errors);
 }
 /**
  * Renders the input field for widget.
  *
  * @param  string $name        The element name
  * @param  string $value       The this widget is checked if value is not null
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetFormInputText
  */
 public function renderInputField($name, $value = null, $attributes = array(), $errors = array())
 {
     return parent::render($name, $value, $attributes, $errors);
 }
 public function render($name, $value = ' ', $attributes = array(), $errors = array())
 {
     $input = parent::render($name, abs($value), $attributes);
     return $input;
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $res = parent::render($name, $value, $attributes, $errors);
     $res .= ' ' . __('Commentaire') . ' (<em>' . __('facultatif') . '</em>) : <input type="text" name="' . str_replace('date', 'comment', $name) . '" value="' . $this->comment_value . '" />';
     return $res;
 }
Exemplo n.º 14
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../bootstrap/unit.php';
$t = new lime_test(5);
$w = new sfWidgetFormInputText();
// ->render()
$t->diag('->render()');
$t->is($w->render('foo'), '<input type="text" name="foo" id="foo" />', '->render() renders the widget as HTML');
$t->is($w->render('foo', 'bar'), '<input type="text" name="foo" value="bar" id="foo" />', '->render() can take a value for the input');
$t->is($w->render('foo', '', array('type' => 'password', 'class' => 'foobar')), '<input type="password" name="foo" value="" class="foobar" id="foo" />', '->render() can take HTML attributes as its third argument');
$w = new sfWidgetFormInputText(array(), array('class' => 'foobar'));
$t->is($w->render('foo'), '<input class="foobar" type="text" name="foo" id="foo" />', '__construct() can take default HTML attributes');
$t->is($w->render('foo', null, array('class' => 'barfoo')), '<input class="barfoo" type="text" name="foo" id="foo" />', '->render() can override default attributes');
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $value = $this->convertToLocaleNumber($value);
     return parent::render($name, $value, $attributes, $errors);
 }
 /**
  * Renders the widget.
  *
  * @param  string $name        The element name
  * @param  string $value       The value selected in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (is_null($value)) {
         $value = array();
     }
     $choices = $this->getOption('choices');
     if ($choices instanceof sfCallable) {
         $choices = $choices->call();
     }
     $associated = array();
     $unassociated = array();
     if (!is_array($value)) {
         $value = array($value);
     }
     foreach ($choices as $key => $option) {
         if (in_array(strval($key), $value)) {
             $associated[$key] = $option;
         } else {
             $unassociated[$key] = $option;
         }
     }
     $size = isset($attributes['size']) ? $attributes['size'] : (isset($this->attributes['size']) ? $this->attributes['size'] : 10);
     $id = $this->generateId($name);
     $error_id = 'error_' . $id;
     // The two select boxes
     $associatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $associated), array('size' => $size, 'class' => $this->getOption('class_select') . '-selected'));
     $unassociatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $unassociated), array('size' => $size, 'class' => $this->getOption('class_select')));
     // The input box used to filter content of unassociated select box
     $filterWidget = new sfWidgetFormInputText(array(), array('class' => $this->getOption('filter_class')));
     // Options to be passed to the renderTag of reset filter image
     $filterResetOptions = array('src' => '/images/remove.png', 'id' => 'filter_' . $id . "_clear", 'class' => 'filter_clear', 'alt' => __('Reset filter'), 'title' => __('Reset filter'));
     $addOptionHTML = '';
     // If add of a value in distant table is possible and activated
     if ($this->getOption('add_active')) {
         // Define the add value input box
         $addOptionWidget = new sfWidgetFormInputText(array(), array('id' => 'add_' . $id, 'class' => $this->getOption('add_class')));
         $addOptionWidget->setLabel(__('Add new value:'));
         // Options to be passed to the renderTag of add option image
         $addImageOptions = array('src' => '/images/add_green.png', 'id' => 'add_' . $id . '_image', 'class' => 'add_option', 'alt' => __('Add value'), 'title' => __('Add value'));
         // Options to be passed to the timer displayed while tryin' to insert a value
         $addTimerImageOptions = array('src' => '/images/loader.gif', 'id' => 'add_' . $id . '_loader', 'style' => 'display:none;');
         $addLinkOptions = array('id' => 'add_' . $id . '_link', 'class' => 'add_option', 'href' => url_for($this->getOption('add_url')));
         $addOptionHTML = $this->renderContentTag('label', $addOptionWidget->getLabel(), array('for' => 'add_' . $id)) . $addOptionWidget->render('add_' . $name) . $this->renderContentTag('a', $this->renderTag('img', $addImageOptions), $addLinkOptions) . $this->renderTag('img', $addTimerImageOptions);
     }
     return strtr($this->getOption('template'), array('%class%' => $this->getOption('class'), '%class_select%' => $this->getOption('class_select'), '%id%' => $id, '%label_associated%' => $this->getOption('label_associated'), '%label_unassociated%' => $this->getOption('label_unassociated'), '%associate%' => sprintf('<a href="#" id="associate_' . $id . '">%s</a>', $this->getOption('associate')), '%unassociate%' => sprintf('<a href="#" id="unassociate_' . $id . '">%s</a>', $this->getOption('unassociate')), '%associated%' => $associatedWidget->render($name), '%unassociated%' => $unassociatedWidget->render('unassociated_' . $name), '%filter%' => $filterWidget->render('filter_' . $name), '%filter_reset%' => $this->renderTag('img', $filterResetOptions), '%add_option%' => $addOptionHTML, '%error_id%' => $error_id));
 }