/** * @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; }
require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(6); $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; // ->configure() $t->diag('->configure()'); try { new sfWidgetFormI18nChoiceLanguage(array('culture' => 'en', 'languages' => array('xx'))); $t->fail('->configure() throws an InvalidArgumentException if a language does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->configure() throws an InvalidArgumentException if a language does not exist'); } $v = new sfWidgetFormI18nChoiceLanguage(array('culture' => 'en', 'languages' => array('fr', 'en'))); $t->is(array_keys($v->getOption('choices')), array('en', 'fr'), '->configure() can restrict the number of languages with the languages option'); // ->render() $t->diag('->render()'); $w = new sfWidgetFormI18nChoiceLanguage(array('culture' => 'fr')); $dom->loadHTML($w->render('language', 'en')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#language option[value="en"]')->getValue(), 'anglais', '->render() renders all languages as option tags'); $t->is(count($css->matchAll('#language option[value="en"][selected="selected"]')->getNodes()), 1, '->render() renders all languages as option tags'); // add_empty $t->diag('add_empty'); $w = new sfWidgetFormI18nChoiceLanguage(array('culture' => 'fr', 'add_empty' => true)); $dom->loadHTML($w->render('language', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#language option[value=""]')->getValue(), '', '->render() renders an empty option if add_empty is true'); $w = new sfWidgetFormI18nChoiceLanguage(array('culture' => 'fr', 'add_empty' => 'foo')); $dom->loadHTML($w->render('language', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#language option[value=""]')->getValue(), 'foo', '->render() renders an empty option if add_empty is true');
<ul> <li class="buttons"> <?php echo gButton(__("Next"), 'type=submit id=next', 'button=true'); ?> </li> </ul> </div> <?php include_partial('sidebar', array('step' => $step)); ?> <div id="content"> <div> <span class="label"> <label for="language"><?php echo __('Please choose the language to use during the installation of Siwapp'); ?> </label> </span> <span class="field"> <?php $lang_selector = new sfWidgetFormI18nChoiceLanguage(array('culture' => $sf_user->getAttribute('language', $preferred_language), 'languages' => CultureTools::getAvailableLanguages())); echo $lang_selector->render('language', $sf_user->getAttribute('language', $preferred_language), array('id' => 'config_language')); ?> </span> </div> <div id="country_container"></div> </div> </form>
function languages_select_tag($name, $value, $attributes = array()) { $f = new sfWidgetFormI18nChoiceLanguage(array('languages' => languagesController::getLanguageCodes())); return $f->render($name, $value, $attributes); }