public function generateLabel($name, $attributes = array()) { $validatorSchema = $this->form->getValidatorSchema(); $class = isset($validatorSchema[$name]) && $validatorSchema[$name]->getOption("required") ? "required" : false; if ($class) { $attributes["class"] = isset($attributes["class"]) ? $attributes["class"] . " {$class}" : $class; } return parent::generateLabel($name, $attributes); }
/** * Generates the label name for the given field name. * * @param string $name The field name * @return string The label name */ public function generateLabelName($name) { $label = parent::generateLabelName($name); $fields = $this->validatorSchema->getFields(); if ($fields[$name] != null) { $field = $fields[$name]; if ($label && $field->hasOption('required') && $field->getOption('required')) { $label .= $this->requiredTemplate; } } return $label; }
public function generateLabel($name, $attributes = array()) { // loop up to find the "required_fields" option $widget = $this->widgetSchema; do { $requiredFields = (array) $widget->getOption('required_fields'); } while ($widget = $widget->getParent()); // add a class (non-destructively) if the field is required if (in_array($this->widgetSchema->generateName($name), $requiredFields)) { $attributes['class'] = isset($attributes['class']) ? $attributes['class'] . ' ' . $this->_requiredLabelClass : $this->_requiredLabelClass; } return parent::generateLabel($name, $attributes); }
public function generateLabelName($name) { $originalCallable = null; if (isset(self::$translationCallable[0]) && self::$translationCallable[0] instanceof opI18N) { $originalCallable = clone self::$translationCallable[0]; self::$translationCallable[0]->titleize = true; } $result = parent::generateLabelName($name); if ($originalCallable) { self::$translationCallable[0] = $originalCallable; } return $result; }
/** * Overloading this method as a way to strip required from labels * * Bit of a hack! * * @param mixed $errors * @return string */ public function formatErrorsForRow($errors) { if (is_array($errors) && $this->getMarkRequired()) { foreach ($errors as $name => $error) { $fixedName = str_replace($this->requiredFormat, '', $name); if ($fixedName != $name) { $errors[$fixedName] = $error; unset($errors[$name]); } } } return parent::formatErrorsForRow($errors); }
<?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(2); $f = new sfWidgetFormSchemaFormatterTable(new sfWidgetFormSchema()); // ->formatRow() $t->diag('->formatRow()'); $output = <<<EOF <tr> <th>label</th> <td><input />help</td> </tr> EOF; $t->is($f->formatRow('label', '<input />', array(), 'help', ''), fix_linebreaks($output), '->formatRow() formats a field in a row'); // ->formatErrorRow() $t->diag('->formatErrorRow()'); $output = <<<EOF <tr><td colspan="2"> <ul class="error_list"> <li>Global error</li> <li>id: required</li> <li>1 > sub_id: required</li> </ul>
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null) { $row = parent::formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null); return strtr($row, array('%error_class%' => count($errors) > 0 ? 'error wrong' : '')); }
/** * Adds an extra wildcard %row_class% that is added to the row format * which will add an additional class if the row has an error * * @see sfWidgetFormSchemaFormatter */ public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null) { $row = parent::formatRow($label, $field, $errors, $help, $hiddenFields); return strtr($row, array('%row_class%' => count($errors) > 0 ? $this->_rowClass . ' ' . $this->_rowErrorClass : $this->_rowClass)); }