From 5729bbc085f2a24c506d9fc70443d9dbfeb35126 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 13 Feb 2014 15:10:20 -0800 Subject: [PATCH] Fix transaction comment bug Summary: form.reset() resets a form to whatever values were present when the form was loaded into the DOM. Instead, grab all the pertinent form bits and set there values to "clear". I don't think there's too much utility in putting this somewhere more general, but it could be something like DOM.clearForm(form) or something. Fixes T3629. Test Plan: repro'd original issue - open legalpad doc (or your favorite application transaction powered app) - type in a comment but do not submit (you are creating a draft) e.g. "foo" - reload page and note comment appears e.g. "foo" - change comment e.g. "foobar" - submit comment - BUG - after submission, the comment reverts to the comment at initial page load e.g. "foo" then after this patch, I can't repro it anymore with these steps - the comment is correctly blank NOTE: this will need to be tested with more complicated forms. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T3629 Differential Revision: https://secure.phabricator.com/D8220 --- resources/celerity/map.php | 20 +++++------ .../transactions/behavior-transaction-list.js | 33 +++++++++++++++++-- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 8d0cb6f235..cfd0fd1465 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -406,7 +406,7 @@ return array( 'rsrc/js/application/search/behavior-reorder-queries.js' => '34397f68', 'rsrc/js/application/slowvote/behavior-slowvote-embed.js' => 'a51fdb2e', 'rsrc/js/application/transactions/behavior-transaction-comment-form.js' => '9084a36f', - 'rsrc/js/application/transactions/behavior-transaction-list.js' => '0dcf1716', + 'rsrc/js/application/transactions/behavior-transaction-list.js' => '5e3da3ad', 'rsrc/js/application/uiexample/JavelinViewExample.js' => 'd4a14807', 'rsrc/js/application/uiexample/ReactorButtonExample.js' => '44524435', 'rsrc/js/application/uiexample/ReactorCheckboxExample.js' => '7ba325ee', @@ -599,7 +599,7 @@ return array( 'javelin-behavior-phabricator-search-typeahead' => 'f6b56f7a', 'javelin-behavior-phabricator-tooltips' => 'e5dd1c6d', 'javelin-behavior-phabricator-transaction-comment-form' => '9084a36f', - 'javelin-behavior-phabricator-transaction-list' => '0dcf1716', + 'javelin-behavior-phabricator-transaction-list' => '5e3da3ad', 'javelin-behavior-phabricator-watch-anchor' => '06e05112', 'javelin-behavior-phame-post-preview' => '61d927ec', 'javelin-behavior-pholio-mock-edit' => '1e1e8bb0', @@ -850,14 +850,6 @@ return array( 1 => 'javelin-install', 2 => 'javelin-dom', ), - '0dcf1716' => - array( - 0 => 'javelin-behavior', - 1 => 'javelin-stratcom', - 2 => 'javelin-workflow', - 3 => 'javelin-dom', - 4 => 'javelin-fx', - ), '0e34ca02' => array( 0 => 'javelin-behavior', @@ -1167,6 +1159,14 @@ return array( 3 => 'javelin-stratcom', 4 => 'javelin-vector', ), + '5e3da3ad' => + array( + 0 => 'javelin-behavior', + 1 => 'javelin-stratcom', + 2 => 'javelin-workflow', + 3 => 'javelin-dom', + 4 => 'javelin-fx', + ), '5f004630' => array( 0 => 'javelin-behavior', diff --git a/webroot/rsrc/js/application/transactions/behavior-transaction-list.js b/webroot/rsrc/js/application/transactions/behavior-transaction-list.js index e9e988367b..6793d6c342 100644 --- a/webroot/rsrc/js/application/transactions/behavior-transaction-list.js +++ b/webroot/rsrc/js/application/transactions/behavior-transaction-list.js @@ -109,11 +109,40 @@ JX.behavior('phabricator-transaction-list', function(config) { var e = JX.DOM.invoke(form, 'willClear'); if (!e.getPrevented()) { - form.reset(); + var ii; + var textareas = JX.DOM.scry(form, 'textarea'); + for (ii = 0; ii < textareas.length; ii++) { + textareas[ii].value = ''; + } + + var inputs = JX.DOM.scry(form, 'input'); + for (ii = 0; ii < inputs.length; ii++) { + switch (inputs[ii].type) { + case 'password': + case 'text': + inputs[ii].value = ''; + break; + case 'checkbox': + case 'radio': + inputs[ii].checked = false; + break; + } + } + + var selects = JX.DOM.scry(form, 'select'); + var jj; + for (ii = 0; ii < selects.length; ii++) { + if (selects[ii].type == 'select-one') { + selects[ii].selectedIndex = 0; + } else { + for (jj = 0; jj < selects[ii].options.length; jj++) { + selects[ii].options[jj].selected = false; + } + } + } } }) .start(); }); - });