Merge lp:~alastair-b/tiqit/dropdown-fix into lp:tiqit

Proposed by Alastair
Status: Needs review
Proposed branch: lp:~alastair-b/tiqit/dropdown-fix
Merge into: lp:tiqit
Diff against target: 54 lines (+18/-0)
2 files modified
static/scripts/tiqit.js (+9/-0)
static/scripts/view.js (+9/-0)
To merge this branch: bzr merge lp:~alastair-b/tiqit/dropdown-fix
Reviewer Review Type Date Requested Status
Sam Stoll Pending
Review via email: mp+299060@code.launchpad.net

Commit message

Improve handling for listboxes to cope with a default value which is not on the list of permitted values (instead set the value to the first permitted value).

Description of the change

Currently, when an editor object is retrieved with a set of permitted values, there is no checking to see if the default value is in the list of permitted values. When an attempt is made to set the editor.value to an invalid value, it ends up set to "" instead.

This change is twofold:
 1. update the editor object retrieval to set editor.value to the first valid value if an invalid default value is specified
 2. update the resetting to default value code in view.js to check if the attempt to set the editor value to the default value failed, and if it did, then restore the known good value which was set up initially when the editor object was retrieved.

This fixes the issue where updating the severity of a bug results in an empty "feature" field instead of the first valid value.

To post a comment you must log in.
Revision history for this message
Martin Morrison (isoschiz) :
Revision history for this message
Alastair (alastair-b) :
lp:~alastair-b/tiqit/dropdown-fix updated
15. By Alastair Palmer <email address hidden>

Review markups: use editor.input.value rather than editor.value.

Unmerged revisions

15. By Alastair Palmer <email address hidden>

Review markups: use editor.input.value rather than editor.value.

14. By Alastair Palmer <email address hidden>

Add handling for the case where the current value of a listbox is not a
permitted value. Instead of accepting the default behavior of the
object's value being set to "", check it and set it to the first known
good value instead.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'static/scripts/tiqit.js'
--- static/scripts/tiqit.js 2014-06-05 14:38:53 +0000
+++ static/scripts/tiqit.js 2016-07-06 12:08:12 +0000
@@ -547,6 +547,10 @@
547 *547 *
548 * The returned object will have an 'input' field that is the actual input548 * The returned object will have an 'input' field that is the actual input
549 * object that values can be read from/set on, and can be disabled/enabled.549 * object that values can be read from/set on, and can be disabled/enabled.
550 *
551 * If the editor object has a restricted set of values *and* a default value
552 * is passed in which is not a permitted value, then the editor's value will
553 * be set to the first item in the array of permitted values.
550 */554 */
551dropdownEditTypes = new Array('Text', 'Number');555dropdownEditTypes = new Array('Text', 'Number');
552function getEditorCommon(field, name, defval, vals, search, rel, parentValFn) {556function getEditorCommon(field, name, defval, vals, search, rel, parentValFn) {
@@ -566,6 +570,11 @@
566 }570 }
567 if (defval) {571 if (defval) {
568 newVal.value = defval;572 newVal.value = defval;
573
574 if (newVal.value != defval) {
575 // Failed to set value, try using the first element of the field
576 newVal.value = vals[0][0];
577 }
569 }578 }
570579
571 newVal.input = newVal;580 newVal.input = newVal;
572581
=== modified file 'static/scripts/view.js' (properties changed: -x to +x)
--- static/scripts/view.js 2015-12-22 15:22:57 +0000
+++ static/scripts/view.js 2016-07-06 12:08:12 +0000
@@ -563,6 +563,7 @@
563 var editor;563 var editor;
564 var value;564 var value;
565 var parent;565 var parent;
566 var old_safe_value;
566567
567 for (child in field.childfields) {568 for (child in field.childfields) {
568 // Generate a new dropdown box with the correct allowed values based569 // Generate a new dropdown box with the correct allowed values based
@@ -587,7 +588,15 @@
587588
588 // Go back to the default value if we are not a checkbox589 // Go back to the default value if we are not a checkbox
589 if (!(field.childfields[child].nodeName == 'INPUT' && field.childfields[child].type == 'checkbox')) {590 if (!(field.childfields[child].nodeName == 'INPUT' && field.childfields[child].type == 'checkbox')) {
591 // Store the current editor value as we know that it's valid.
592 old_safe_value = editor.input.value;
590 editor.input.value = old_editor.input.defaultValue;593 editor.input.value = old_editor.input.defaultValue;
594
595 if (editor.input.value != old_editor.input.defaultValue) {
596 // If the current default value couldn't be set (i.e. it's not a valid value) then restore the
597 // old safe value.
598 editor.input.value = old_safe_value;
599 }
591 }600 }
592 601
593 // Add the event listener(s) updateChildrenView and checkFormValidity602 // Add the event listener(s) updateChildrenView and checkFormValidity

Subscribers

People subscribed via source and target branches