/**
  * 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())
 {
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18N'));
     $default_text = $this->getOption('default_text', null);
     if ($default_text) {
         $default_text = __($default_text);
     } else {
         $default_text = $this->getOption('multiple') ? __("Select Some Options") . '...' : __("Select an Option") . '...';
     }
     $align_right = $this->getOption('align_right', null);
     if ($align_right) {
         if (!isset($attributes['class'])) {
             $attributes['class'] = '';
         }
         $attributes['class'] .= ' chzn-select chzn-rtl';
     }
     if (!isset($attributes['style'])) {
         $attributes['style'] = 'min-width: 300px; max-width: 700px;';
     } else {
         $attributes['style'] = '; min-width: 300px; max-width: 700px;';
     }
     $html = parent::render($name, $value, $attributes, $errors);
     $html .= dcWidgetFormChosenChoice::getWidgetInitializationJS($this->generateId($name), $value, $default_text);
     return $html;
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (!$value) {
         $value = $this->getAttribute('value');
     }
     return parent::render($name, $value, $attributes, $errors);
 }
    /**
     * @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())
    {
        $id = $this->generateId($name);

        $return = parent::render($name, $value, $attributes, $errors);

        $return .= sprintf(<<<EOF
<script type="text/javascript">
function formatResult(item)
{
    return item.text;
}

jQuery("#%s").select2(
{
    width:              '%s',
    allowClear:         %s
});
</script>
EOF
            ,
            $id,
            $this->getOption('width'),
            $this->getOption('add_empty') == true ? 'true' : 'false'
        );

        return $return;
    }
    /**
     * 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();
        foreach ($choices as $key => $option) {
            if (in_array(strval($key), $value)) {
                $associated[$key] = $option;
            } else {
                $unassociated[$key] = $option;
            }
        }
        $associatedWidget = new sfWidgetFormChoice(array_merge($this->getOption('list_options'), array('choices' => $associated, 'multiple' => true, 'expanded' => true)));
        return strtr($this->getOption('template'), array('%class%' => 'USJjQueryUIAutocomplete', '%id%' => $this->generateId($name), '%list%' => $associatedWidget->render($name, $value), '%autocomplete%' => $this->renderTag('input', array('type' => 'text', 'name' => 'autocomplete_' . $name)) . sprintf(<<<EOF
\t<script type="text/javascript">
\t  jQuery(document).ready(function() {

  \t    jQuery('#%s').focus(function(){ \$(this).val(''); }).trigger('focus');
\t    jQuery('#%s').blur(function(){ \$(this).val('%s'); }).trigger('blur');

\t    if (!\$('div#%s_list ul.checkbox_list').length) {
\t      \$('div#%s_list').append('<ul class="checkbox_list"></ul>');
\t    }

\t    jQuery('#%s').autocomplete({
\t     source: %s,
\t     select: function(event, ui) {
\t       if (!\$('#%s_'+ui.item.id).length) {
                 var ul = \$('div#%s_list ul.checkbox_list');
\t\t \$('<li><input type="checkbox" checked="checked" id="%s_'+ui.item.id+'" value="'+ui.item.id+'" name="%s"> <label for="%s_'+ui.item.id+'">'+ui.item.value+'</label></li>').prependTo(ul);
\t       }
\t       \$(this).trigger('blur');
\t    }
\t});

\tjQuery('div#%s_list').change(function(e){
\t  var elt = \$(e.target);
\t  if (\$(elt).is(':not(:checked)')) {
\t    \$(elt).parent('li').animate({'backgroundColor':'#fb6c6c'},300);
\t  }
\t  setTimeout(function(){
           if (\$(elt).is(':not(:checked)')) {
\t     \$(elt).parent('li').slideUp(300,function() { \$(this).remove() });
\t   } else {
\t     \$(elt).parent('li').css({'backgroundColor':'#fff'});
\t   }
\t },3000);
\t});
      });
</script>
EOF
, $this->generateId('autocomplete_' . $name), $this->generateId('autocomplete_' . $name), $this->getOption('help'), $this->generateId($name), $this->generateId($name), $this->generateId('autocomplete_' . $name), '"' . $this->getOption('source') . '"', $this->generateId($name), $this->generateId($name), $this->generateId($name), $name, $this->generateId($name), $this->generateId($name))));
    }
Exemplo n.º 5
0
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $field = parent::render($name, $value, $attributes, $errors);
     $name = " " . $this->getOption('name') . " ";
     $module = $this->getOption('module');
     $link = '<a href="' . sfContext::getInstance()->getController()->genUrl("{$module}/deleteInstitucion") . '?idm=' . $this->getOption('parent_id') . '&idi=' . $this->getOption('model_id') . '" onclick="if (confirm(\'sure?\')) { return true; };return false;"><img src="/sfPropelPlugin/images/delete.png" alt="borrar" /></a>';
     return (!$this->getOption('name') ? $field : '') . $name . ($this->getOption('name') ? $link : '');
 }
Exemplo n.º 6
0
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $login = new sfWidgetFormInput();
     $login->setAttribute('readonly', 'readonly');
     $choices = array('0' => 'etu.utc.fr', '1' => 'utc.fr', '2' => 'escom.fr');
     $domaine = new sfWidgetFormChoice(array('choices' => $choices));
     return $login->render("nickname_email") . " @ " . $domaine->render($name);
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (false !== $this->getOption('add_empty')) {
         $choices[''] = true === $this->getOption('add_empty') ? '' : $this->translate($this->getOption('add_empty'));
         $this->setOption('choices', array_merge($choices, $this->getOption('choices')));
     }
     return parent::render($name, $value, $attributes, $errors);
 }
  public function render($name, $value = null, $attributes = array(), $errors = array())
  {
    $current_catalogue = strval($this->parent->getFormFormatter()->getTranslationCatalogue());

    $this->parent->getFormFormatter()->setTranslationCatalogue($this->getOption('catalogue'));

    $response = parent::render($name, $value, $attributes, $errors);

    $this->parent->getFormFormatter()->setTranslationCatalogue($current_catalogue);

    return $response;
  }
 /**
  * Render field
  * 
  * @param   string  $name       Element name
  * @param   string  $value      Element value
  * @param   array   $attributes HTML attributes [optional]
  * @param   array   $errors     Errors for the field [optional]
  * @return  string  XHTML compliant tag
  * @author  relo_san
  * @since   february 8, 2010
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $s[] = '<script type="text/javascript">';
     $s[] = 'jQuery(document).ready(function(){';
     $s[] = '$(\'#' . $this->generateId($this->getOption('parent')) . '\').change(function(){';
     $s[] = 'var objectId=' . ($value ? $value : 'null') . ';$.getJSON(\'' . $this->getOption('url') . '\',';
     $s[] = '{id:$(\'#' . $this->generateId($this->getOption('parent')) . '\').val(),ajax:\'true\'},';
     $s[] = 'function(j){var options=\'\';for(var i=0;i<j.length;i++){';
     $s[] = 'options+=\'<option value="\'+j[i].id+\'"\'+(j[i].id==objectId?\' selected=[selected]\':\'\')+\'>\'+j[i].value+\'</option>\';';
     $s[] = '}$(\'select#' . $this->generateId($name) . '\').html(options);});});});';
     $s[] = '</script>';
     return parent::render($name, $value, $attributes, $errors) . implode($s);
 }
    /**
     * @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())
    {
        $script = <<<EOS
\t<script>
\t\$(function() {
\t\tvar select = \$( "select[name='rt_comment[rating]']" ).hide();
\t\tvar slider = \$( "<div id='rating' style='display:inline-block; width:200px'></div>" ).insertAfter( select ).slider({
\t\t\tmin: 1,
\t\t\tmax: 11,
\t\t\trange: "min",
\t\t\tvalue: select[ 0 ].selectedIndex + 1,
\t\t\tslide: function( event, ui ) {
              \$("#ratingSelection").html((ui.value - 1) / 2);
              select[ 0 ].selectedIndex = ui.value - 1;
\t\t\t}
\t\t});
\t\tselect.change(function() {
          slider.slider( "value", this.selectedIndex + 1 );
\t\t});
\t});
\t</script>
EOS;
        return '0/5 ' . parent::render($name, $value, $attributes, $errors) . ' <span id="ratingSelection">5</span>/5' . $script;
    }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $choice = new sfWidgetFormChoice(array('choices' => $this->calculateWeeks()));
     return $choice->render($name, $this->getIndex(strtotime($value)), $attributes, $errors);
 }
Exemplo n.º 12
0
<?php

$analyze = $analyze->getRawValue();
?>

<div class="row form-group">
  <div class="col-md-3">
    <label class="control-label" for="cost-criteria">Cost variable</label>
    <span class="glyphicon glyphicon-info-sign help-info"
          data-toggle="tooltip" title="Select the cost variable you want to allocate"
          data-placement="right"></span>
    <?php 
$widget = new sfWidgetFormChoice(array('choices' => $analyze->getCriteria()), array('class' => 'form-control'));
echo $widget->render('cost-criteria');
?>
  </div>

  <div class="col-md-2">
    <label class="control-label">Pool</label>
    <span class="glyphicon glyphicon-info-sign help-info" data-toggle="tooltip" title="Specify the total sum of resources available for the selected cost variable" data-placement="right"></span>
    <input id="cost-pool" name="pool" type="text" class="form-control">
  </div>

  <div class="col-md-1" style="padding-top:7px;">
    <br>
    <a id="allocate" class="btn btn-primary" href="javascript:void(0)">Allocate</a>
  </div>

  <div class="col-md-2">
    <label class="control-label">Unallocated</label>
    <span class="glyphicon glyphicon-info-sign help-info" data-toggle="tooltip" title="What is left after the current allocation" data-placement="right"></span>
        return array('/path/to/a/file.js');
    }
    public function getStylesheets()
    {
        return array('/path/to/a/file.css' => 'all');
    }
}
$w->setOption('renderer_class', 'MyWidget');
$t->is(get_class($w->getRenderer()), 'MyWidget', '->getRenderer() uses the renderer_class as the widget class if provided');
$w->setOption('renderer_class', null);
$w->setOption('renderer', new MyWidget(array('choices' => array())));
$t->is(get_class($w->getRenderer()), 'MyWidget', '->getRenderer() uses the renderer as the widget if provided');
// ->render()
$t->diag('->render()');
$w = new sfWidgetFormChoice(array('choices' => array()));
$t->like($w->render('foo'), '/<select name="foo" id="foo">/', '->render() renders a select tag by default');
$w->setOption('multiple', true);
$t->like($w->render('foo'), '/<select name="foo\\[\\]" multiple="multiple" id="foo">/', '->render() adds a multiple attribute for multiple selects');
$w->setOption('expanded', true);
$t->like($w->render('foo'), '/<ul class="checkbox_list">/', '->render() uses a checkbox list when expanded and multiple are true');
$w->setOption('multiple', false);
$t->like($w->render('foo'), '/<ul class="radio_list">/', '->render() uses a checkbox list when expanded is true and multiple is false');
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
$w = new sfWidgetFormChoice(array('choices' => array()));
$w->setOption('renderer_class', 'MyWidget');
$t->is($w->getJavaScripts(), array('/path/to/a/file.js'), '->getJavaScripts() returns the stylesheets of the renderer widget');
$t->is($w->getStylesheets(), array('/path/to/a/file.css' => 'all'), '->getStylesheets() returns the JavaScripts of the renderer widget');
// __clone()
$t->diag('__clone()');
$w = new sfWidgetFormChoice(array('choices' => new sfCallable(array($w, 'foo'))));
Exemplo n.º 14
0
function select_tag($name = '', $value = '', $options, $attributes = array())
{
    $f = new sfWidgetFormChoice($options);
    return $f->render($name, $value, $attributes);
}
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $res = parent::render($name, $value, $attributes, $errors);
     $res .= "\n    <script type=\"text/javascript\">\n    \$(function() {\t\n      \$('#" . $this->getOption('other_id') . "').bind('change', function(){\n        \$('#" . $this->generateId($name) . "').otherlist({\n          'other': '" . $this->getOption('other_id') . "',\n          'default': '" . $value . "'\n        })\n      })\n      \$('#" . $this->getOption('other_id') . "').trigger('change');  \n    })\n    </script>";
     return $res;
 }
 /**
  * Implementaчуo de sfWidgetFormInput::render, acrescida de TRIM no valor do campo
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     return parent::render($name, trim($value), $attributes, $errors);
 }
Exemplo n.º 17
0
$t->like($w->render('foo'), '/<select name="foo" id="barID_foo">/', '->render() uses the id format specified');
$w->setIdFormat('%s');
$w->setOption('multiple', true);
$t->like($w->render('foo'), '/<select name="foo\\[\\]" multiple="multiple" id="foo">/', '->render() adds a multiple attribute for multiple selects');
$w->setOption('expanded', true);
$t->like($w->render('foo'), '/<ul class="checkbox_list">/', '->render() uses a checkbox list when expanded and multiple are true');
$w->setOption('multiple', false);
$t->like($w->render('foo'), '/<ul class="radio_list">/', '->render() uses a checkbox list when expanded is true and multiple is false');
// choices are translated
$t->diag('choices are translated');
$ws = new sfWidgetFormSchema();
$ws->addFormFormatter('stub', new FormFormatterStub());
$ws->setFormFormatterName('stub');
$w = new sfWidgetFormChoice(array('choices' => array('foo' => 'bar', 'foobar' => 'foo')));
$w->setParent($ws);
$dom->loadHTML($w->render('foo'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#foo option[value="foo"]')->getValue(), 'translation[bar]', '->render() translates the options');
$t->is($css->matchSingle('#foo option[value="foobar"]')->getValue(), 'translation[foo]', '->render() translates the options');
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
$w = new sfWidgetFormChoice(array('choices' => array()));
$w->setOption('renderer_class', 'MyWidget');
$t->is($w->getJavaScripts(), array('/path/to/a/file.js'), '->getJavaScripts() returns the stylesheets of the renderer widget');
$t->is($w->getStylesheets(), array('/path/to/a/file.css' => 'all'), '->getStylesheets() returns the JavaScripts of the renderer widget');
// __clone()
$t->diag('__clone()');
$w = new sfWidgetFormChoice(array('choices' => new sfCallable(array($w, 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($w1), '__clone() changes the choices is a callable and the object is an instance of the current object');
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $attributes['data-refresh'] = $value;
     return parent::render($name, $value, $attributes, $errors);
 }