From 64bfd7630eb913c1d7c7ced8a20a162883ba62a8 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Fri, 21 Jun 2013 15:13:48 -0700 Subject: [PATCH] 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 --- ...hestAuxiliaryFieldDefaultSpecification.php | 19 +++++++++++-------- .../ManiphestTaskEditController.php | 9 ++++++++- webroot/rsrc/css/phui/phui-form.css | 3 ++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php b/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php index 8338c6dc6a..980b87967b 100644 --- a/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php +++ b/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php @@ -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()); } diff --git a/src/applications/maniphest/controller/ManiphestTaskEditController.php b/src/applications/maniphest/controller/ManiphestTaskEditController.php index cba05b3ec6..f578e37e0b 100644 --- a/src/applications/maniphest/controller/ManiphestTaskEditController.php +++ b/src/applications/maniphest/controller/ManiphestTaskEditController.php @@ -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()); diff --git a/webroot/rsrc/css/phui/phui-form.css b/webroot/rsrc/css/phui/phui-form.css index 09139df1ad..92bdacc40e 100644 --- a/webroot/rsrc/css/phui/phui-form.css +++ b/webroot/rsrc/css/phui/phui-form.css @@ -129,6 +129,7 @@ textarea::-webkit-input-placeholder { } -select[disabled="disabled"] { +select[disabled="disabled"], +input[disabled="disabled"] { opacity: 0.5; }