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

View file

@ -123,8 +123,15 @@ final class ManiphestTaskEditController extends ManiphestController {
$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_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()) {
$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;
}