Merge lp:~methanal-developers/methanal/control-reset into lp:methanal

Proposed by Jonathan Jacobs
Status: Merged
Approved by: Tristan Seligmann
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~methanal-developers/methanal/control-reset
Merge into: lp:methanal
Diff against target: 109 lines (+39/-7)
2 files modified
methanal/js/Methanal/View.js (+38/-7)
methanal/view.py (+1/-0)
To merge this branch: bzr merge lp:~methanal-developers/methanal/control-reset
Reviewer Review Type Date Requested Status
Tristan Seligmann Approve
Review via email: mp+19946@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tristan Seligmann (mithrandi) wrote :

35 + self.inputNode.checked = value !== undefined && value !== null;

This sets checked to true if value is false; that doesn't seem to make much sense to me. How about:

self.inputNode.checked = !!value;

review: Needs Fixing
133. By Jonathan Jacobs

Fix broken boolean logic for CheckboxInput.setValue.

Revision history for this message
Jonathan Jacobs (jjacobs) wrote :

> 35 + self.inputNode.checked = value !== undefined && value !== null;
>
> This sets checked to true if value is false; that doesn't seem to make much
> sense to me. How about:
>
> self.inputNode.checked = !!value;

Quite right. Done.

Revision history for this message
Tristan Seligmann (mithrandi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'methanal/js/Methanal/View.js'
2--- methanal/js/Methanal/View.js 2010-02-22 09:05:55 +0000
3+++ methanal/js/Methanal/View.js 2010-02-23 14:25:25 +0000
4@@ -783,10 +783,6 @@
5 * Reset form inputs to their initial values.
6 */
7 function reset(self) {
8- // XXX: Use the DOM function to reset for values that might not
9- // otherwise be reset, like password confirmations etc. Ideally
10- // each control's reset method should take care of these.
11- self.node.reset();
12 for (var name in self.controls) {
13 self.getControl(name).reset();
14 }
15@@ -1670,6 +1666,14 @@
16 },
17
18
19+ function reset(self) {
20+ Methanal.View.PrePopulatingTextInput.upcall(self, 'reset');
21+ var targetControl = self.getTargetControl();
22+ targetControl.setValue(self.inputNode.value);
23+ targetControl.onChange(targetControl.inputNode);
24+ },
25+
26+
27 /**
28 * Get the instance of the target control.
29 */
30@@ -1699,6 +1703,11 @@
31 * Checkbox input.
32 */
33 Methanal.View.FormInput.subclass(Methanal.View, 'CheckboxInput').methods(
34+ function setValue(self, value) {
35+ self.inputNode.checked = !!value;
36+ },
37+
38+
39 function getValue(self) {
40 return self.inputNode.checked;
41 });
42@@ -1755,6 +1764,12 @@
43 * A dropdown input.
44 */
45 Methanal.View.FormInput.subclass(Methanal.View, 'SelectInput').methods(
46+ function __init__(self, node, args) {
47+ Methanal.View.SelectInput.upcall(self, '__init__', node, args);
48+ self._placeholderInserted = false;
49+ },
50+
51+
52 /**
53 * Create an C{option} DOM node.
54 *
55@@ -1778,9 +1793,17 @@
56 * Insert a placeholder C{option} node.
57 */
58 function _insertPlaceholder(self) {
59- var optionNode = self.insert(
60- '', self.label, self.inputNode.options[0] || null);
61+ if (self._placeholderInserted) {
62+ return;
63+ }
64+
65+ var before = self.inputNode.getElementsByTagName('optgroup')[0];
66+ if (before === undefined) {
67+ before = self.inputNode.options[0];
68+ }
69+ var optionNode = self.insert('', self.label, before || null);
70 Methanal.Util.addElementClass(optionNode, 'embedded-label');
71+ self._placeholderInserted = true;
72 },
73
74
75@@ -1807,7 +1830,9 @@
76 if (before !== null) {
77 // In browsers before IE8, the second argument to "add" is an
78 // *index*. Great, thanks IE!
79- index = before.index;
80+
81+ // The index of an OPTGROUP is always -1, great.
82+ index = before.tagName == 'OPTGROUP' ? 0 : before.index;
83 }
84 self.inputNode.add(optionNode, index);
85 }
86@@ -2212,6 +2237,12 @@
87 },
88
89
90+ function reset(self) {
91+ Methanal.View.VerifiedPasswordInput.upcall(self, 'reset');
92+ self._confirmPasswordNode.value = self.inputNode.value;
93+ },
94+
95+
96 /**
97 * Set the password strength criteria.
98 *
99
100=== modified file 'methanal/view.py'
101--- methanal/view.py 2010-02-22 21:30:22 +0000
102+++ methanal/view.py 2010-02-23 14:25:25 +0000
103@@ -92,6 +92,7 @@
104 L{LiveForm} action for resetting a form's controls.
105 """
106 jsClass = u'Methanal.View.ResetAction'
107+ allowViewOnly = True
108 defaultName = u'Reset'
109 type = 'reset'
110

Subscribers

People subscribed via source and target branches