1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-01 19:22:42 +01:00

Allow date custom field to be blank

Summary:
Currently it's not allowed to be left blank (even with required: false)

Fixes T3343

Test Plan: Use the custom date field.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, chad

Maniphest Tasks: T3343

Differential Revision: https://secure.phabricator.com/D6251
This commit is contained in:
Gareth Evans 2013-06-21 15:13:48 -07:00 committed by epriestley
parent 8e8057c6fe
commit 64bfd7630e
3 changed files with 21 additions and 10 deletions

View file

@ -100,6 +100,9 @@ class ManiphestAuxiliaryFieldDefaultSpecification
case self::TYPE_DATE: case self::TYPE_DATE:
$control = new AphrontFormDateControl(); $control = new AphrontFormDateControl();
$control->setUser($this->getUser()); $control->setUser($this->getUser());
if (!$this->isRequired()) {
$control->setAllowNull(true);
}
break; break;
case self::TYPE_REMARKUP: case self::TYPE_REMARKUP:
$control = new PhabricatorRemarkupControl(); $control = new PhabricatorRemarkupControl();
@ -132,7 +135,9 @@ class ManiphestAuxiliaryFieldDefaultSpecification
(bool)$this->getValue()); (bool)$this->getValue());
break; break;
case self::TYPE_DATE: case self::TYPE_DATE:
if ($this->getValue() > 0) {
$control->setValue($this->getValue()); $control->setValue($this->getValue());
}
$control->setName('auxiliary_date_'.$this->getAuxiliaryKey()); $control->setName('auxiliary_date_'.$this->getAuxiliaryKey());
break; break;
case self::TYPE_USER: case self::TYPE_USER:
@ -201,7 +206,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
case self::TYPE_USERS: case self::TYPE_USERS:
return json_encode($this->getValue()); return json_encode($this->getValue());
default: default:
return $this->getValue(); return (int)$this->getValue();
} }
} }
@ -216,9 +221,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
break; break;
case self::TYPE_DATE: case self::TYPE_DATE:
$value = (int)$value; $value = (int)$value;
if ($value <= 0) { $this->setDefaultValue($value);
return $this->setDefaultValue($value);
}
break; break;
default: default:
break; break;
@ -243,7 +246,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
case self::TYPE_SELECT: case self::TYPE_SELECT:
return true; return true;
case self::TYPE_DATE: case self::TYPE_DATE:
if ((int)$this->getValue() <= 0) { if ((int)$this->getValue() <= 0 && $this->isRequired()) {
throw new ManiphestAuxiliaryFieldValidationException( throw new ManiphestAuxiliaryFieldValidationException(
pht( pht(
'%s must be a valid date.', '%s must be a valid date.',
@ -367,7 +370,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
// fields normally, users can change the type of an existing field and // fields normally, users can change the type of an existing field and
// leave us with uninterpretable data in old transactions. // leave us with uninterpretable data in old transactions.
if ((int)$new <= 0) { if ((int)$new <= 0) {
$new_display = "(invalid epoch timestamp: {$new})"; $new_display = "none";
} else { } else {
$new_display = phabricator_datetime($new, $this->getUser()); $new_display = phabricator_datetime($new, $this->getUser());
} }
@ -375,7 +378,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
$desc = "set field '{$label}' to '{$new_display}'"; $desc = "set field '{$label}' to '{$new_display}'";
} else { } else {
if ((int)$old <= 0) { if ((int)$old <= 0) {
$old_display = "(invalid epoch timestamp: {$old})"; $old_display = "none";
} else { } else {
$old_display = phabricator_datetime($old, $this->getUser()); $old_display = phabricator_datetime($old, $this->getUser());
} }

View file

@ -123,8 +123,15 @@ final class ManiphestTaskEditController extends ManiphestController {
$errors[] = pht('Title is required.'); $errors[] = pht('Title is required.');
} }
foreach ($aux_fields as $aux_field) { foreach ($aux_fields as $aux_arr_key => $aux_field) {
$aux_field->setValueFromRequest($request); $aux_field->setValueFromRequest($request);
$aux_key = $aux_field->getAuxiliaryKey();
$aux_old_value = $task->getAuxiliaryAttribute($aux_key);
if ((int)$aux_old_value === $aux_field->getValueForStorage()) {
unset($aux_fields[$aux_arr_key]);
continue;
}
if ($aux_field->isRequired() && !$aux_field->getValue()) { if ($aux_field->isRequired() && !$aux_field->getValue()) {
$errors[] = pht('%s is required.', $aux_field->getLabel()); $errors[] = pht('%s is required.', $aux_field->getLabel());

View file

@ -129,6 +129,7 @@ textarea::-webkit-input-placeholder {
} }
select[disabled="disabled"] { select[disabled="disabled"],
input[disabled="disabled"] {
opacity: 0.5; opacity: 0.5;
} }