Skip to content

Commit

Permalink
(fixed #1147 BP from #930) fixed error of the value/maximum in the ed…
Browse files Browse the repository at this point in the history
…it page of the profile item
  • Loading branch information
Tajima Itsuro committed Jun 8, 2010
1 parent 1369244 commit 5777e38
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
28 changes: 27 additions & 1 deletion apps/pc_backend/modules/profile/templates/editSuccess.php
Expand Up @@ -65,7 +65,21 @@
<?php echo $form['value_type']->renderRow() ?>
<tr>
<th><?php echo $form['value_min']->renderLabel() ?><?php echo $form['value_max']->renderLabel() ?></th>
<td><?php echo $form['value_min']->render() ?><?php echo $form['value_max']->render() ?></td>
<td>
<?php if ($form['value_min']->hasError()): ?>
<?php $error = $form['value_min']->getError() ?>
<?php $formatter = $form['value_min']->getParent()->getWidget()->getFormFormatter() ?>
<?php $msg = $form['value_min']->renderLabel().': '.$formatter->translate($error->getMessageFormat(), $error->getArguments()) ?>
<?php echo $formatter->formatErrorsForRow($msg) ?>
<?php endif ?>
<?php if ($form['value_max']->hasError()): ?>
<?php $error = $form['value_max']->getError() ?>
<?php $formatter = $form['value_max']->getParent()->getWidget()->getFormFormatter() ?>
<?php $msg = $form['value_max']->renderLabel().': '.$formatter->translate($error->getMessageFormat(), $error->getArguments()) ?>
<?php echo $formatter->formatErrorsForRow($msg) ?>
<?php endif ?>
<?php echo $form['value_min']->render() ?><?php echo $form['value_max']->render() ?>
</td>
</tr>
<?php echo $form['value_regexp']->renderRow(array('class' => 'advanced')) ?>
</table>
Expand All @@ -79,6 +93,18 @@
<li><code>YYYY/MM/DD HH:MM:SS</code> 形式で入力(例:<code>2009/01/01 23:59:21</code></li>
<li>その他、 PHP の <code>strtotime()</code> 関数が解釈することのできる特殊な文字列が利用可能</li>
</ul>
<?php if ($form['value_min']->hasError()): ?>
<?php $error = $form['value_min']->getError() ?>
<?php $formatter = $form['value_min']->getParent()->getWidget()->getFormFormatter() ?>
<?php $msg = $form['value_min']->renderLabel().': '.$formatter->translate($error->getMessageFormat(), $error->getArguments()) ?>
<?php echo $formatter->formatErrorsForRow($msg) ?>
<?php endif ?>
<?php if ($form['value_max']->hasError()): ?>
<?php $error = $form['value_max']->getError() ?>
<?php $formatter = $form['value_max']->getParent()->getWidget()->getFormFormatter() ?>
<?php $msg = $form['value_max']->renderLabel().': '.$formatter->translate($error->getMessageFormat(), $error->getArguments()) ?>
<?php echo $formatter->formatErrorsForRow($msg) ?>
<?php endif ?>
<?php echo $form['value_min']->render() ?><?php echo $form['value_max']->render() ?>
</td>
</tr>
Expand Down
21 changes: 11 additions & 10 deletions lib/form/doctrine/ProfileForm.class.php
Expand Up @@ -54,7 +54,6 @@ public function configure()
new sfValidatorDoctrineUnique(array('model' => 'Profile', 'column' => array('name')), array('invalid' => 'Already exist.'))
);

$this->mergePostValidator(new sfValidatorCallback(array('callback' => array('ProfileForm', 'advancedValidator'))));
$this->mergePostValidator(new sfValidatorCallback(array('callback' => array('ProfileForm', 'validateName'))));
$this->setValidator('default_public_flag', new sfValidatorChoice(array('choices' => array_keys(Doctrine::getTable('Profile')->getPublicFlags()))));
$this->setValidator('value_min', new sfValidatorPass());
Expand Down Expand Up @@ -87,26 +86,28 @@ public function configure()
$this->embedI18n(array('ja_JP'));
}

static public function advancedValidator($validator, $values)
public function bind($params)
{
if ($values['form_type'] === 'input' || $values['form_type'] === 'textarea')
if ($params['form_type'] === 'input' || $params['form_type'] === 'textarea')
{
$validator = new sfValidatorInteger(array('required' => false));
$values['value_min'] = $validator->clean($values['value_min']);
$values['value_max'] = $validator->clean($values['value_max']);
$this->setValidator('value_min', $validator);
$validator = new sfValidatorInteger(array('required' => false));
$this->setValidator('value_max', $validator);
}
elseif ($values['form_type'] === 'date')
elseif ($params['form_type'] === 'date')
{
$validator = new opValidatorDate(array('required' => false));
$validator->clean($values['value_min']);
$validator->clean($values['value_max']);
$this->setValidator('value_min', $validator);
$validator = new opValidatorDate(array('required' => false));
$this->setValidator('value_max', $validator);
}
elseif ($values['value_min'] || $values['value_max'])
elseif ($params['value_min'] || $params['value_max'])
{
throw new sfValidatorError($validator, 'invalid');
}

return $values;
return parent::bind($params);
}

static public function validateName($validator, $values)
Expand Down
3 changes: 2 additions & 1 deletion lib/validator/opValidatorDate.class.php
Expand Up @@ -39,12 +39,13 @@ protected function doClean($value)
}
else if (!ctype_digit($value))
{
$obj = new DateTime($value);
$obj = date_create($value);
}

if ($obj instanceof DateTime)
{
$clean = $obj;
throw new sfValidatorError($this, 'invalid', array('value' => $value));
}
else
{
Expand Down

0 comments on commit 5777e38

Please sign in to comment.