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
1=== modified file 'static/scripts/tiqit.js'
2--- static/scripts/tiqit.js 2014-06-05 14:38:53 +0000
3+++ static/scripts/tiqit.js 2016-07-06 12:08:12 +0000
4@@ -547,6 +547,10 @@
5 *
6 * The returned object will have an 'input' field that is the actual input
7 * object that values can be read from/set on, and can be disabled/enabled.
8+ *
9+ * If the editor object has a restricted set of values *and* a default value
10+ * is passed in which is not a permitted value, then the editor's value will
11+ * be set to the first item in the array of permitted values.
12 */
13 dropdownEditTypes = new Array('Text', 'Number');
14 function getEditorCommon(field, name, defval, vals, search, rel, parentValFn) {
15@@ -566,6 +570,11 @@
16 }
17 if (defval) {
18 newVal.value = defval;
19+
20+ if (newVal.value != defval) {
21+ // Failed to set value, try using the first element of the field
22+ newVal.value = vals[0][0];
23+ }
24 }
25
26 newVal.input = newVal;
27
28=== modified file 'static/scripts/view.js' (properties changed: -x to +x)
29--- static/scripts/view.js 2015-12-22 15:22:57 +0000
30+++ static/scripts/view.js 2016-07-06 12:08:12 +0000
31@@ -563,6 +563,7 @@
32 var editor;
33 var value;
34 var parent;
35+ var old_safe_value;
36
37 for (child in field.childfields) {
38 // Generate a new dropdown box with the correct allowed values based
39@@ -587,7 +588,15 @@
40
41 // Go back to the default value if we are not a checkbox
42 if (!(field.childfields[child].nodeName == 'INPUT' && field.childfields[child].type == 'checkbox')) {
43+ // Store the current editor value as we know that it's valid.
44+ old_safe_value = editor.input.value;
45 editor.input.value = old_editor.input.defaultValue;
46+
47+ if (editor.input.value != old_editor.input.defaultValue) {
48+ // If the current default value couldn't be set (i.e. it's not a valid value) then restore the
49+ // old safe value.
50+ editor.input.value = old_safe_value;
51+ }
52 }
53
54 // Add the event listener(s) updateChildrenView and checkFormValidity

Subscribers

People subscribed via source and target branches