Merge lp:~methanal-developers/methanal/1250847-simpleform-validation into lp:methanal

Proposed by Jonathan Jacobs
Status: Merged
Approved by: Tristan Seligmann
Approved revision: 201
Merged at revision: 199
Proposed branch: lp:~methanal-developers/methanal/1250847-simpleform-validation
Merge into: lp:methanal
Diff against target: 81 lines (+24/-3)
2 files modified
methanal/js/Methanal/View.js (+11/-3)
methanal/js/Methanal/Widgets.js (+13/-0)
To merge this branch: bzr merge lp:~methanal-developers/methanal/1250847-simpleform-validation
Reviewer Review Type Date Requested Status
Tristan Seligmann Approve
Review via email: mp+195056@code.launchpad.net
To post a comment you must log in.
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 2012-07-30 15:36:53 +0000
3+++ methanal/js/Methanal/View.js 2013-11-13 13:18:25 +0000
4@@ -1437,14 +1437,18 @@
5 Methanal.View.LiveForm.subclass(Methanal.View, 'SimpleForm').methods(
6 function __init__(self, node, controlNames) {
7 Methanal.View.SimpleForm.upcall(
8- self, '__init__', node, {'viewOnly': true}, controlNames);
9+ self, '__init__', node, {}, controlNames);
10 self.hideModificationIndicator = true;
11+ self.valid = true;
12 },
13
14
15 function nodeInserted(self) {
16 // Explicitly override LiveForm's "nodeInserted" method, most of the
17 // nodes it attempts to find will not exist in a simple form.
18+ if (self.viewOnly === undefined && self.widgetParent.getForm) {
19+ self.viewOnly = self.widgetParent.getForm().viewOnly;
20+ }
21 },
22
23
24@@ -1454,11 +1458,13 @@
25
26
27 function setValid(self) {
28+ self.valid = true;
29 self.widgetParent.clearError();
30 },
31
32
33 function setInvalid(self, invalidControls) {
34+ self.valid = false;
35 self.widgetParent.setError('');
36 });
37
38@@ -1668,8 +1674,10 @@
39 Methanal.Util.addElementClass(self.node, 'methanal-control-error');
40 self.error = error;
41 self.widgetParent.checkForErrors();
42- self._errorTooltip.setText(self.error);
43- self._errorTooltip.show();
44+ if (self.error && self.error.length) {
45+ self._errorTooltip.setText(self.error);
46+ self._errorTooltip.show();
47+ }
48 },
49
50
51
52=== modified file 'methanal/js/Methanal/Widgets.js'
53--- methanal/js/Methanal/Widgets.js 2012-11-21 06:18:32 +0000
54+++ methanal/js/Methanal/Widgets.js 2013-11-13 13:18:25 +0000
55@@ -1362,6 +1362,14 @@
56 function resultChanged(self, control) {
57 },
58
59+ function setInvalid(self, invalidControls) {
60+ Methanal.Widgets.LookupForm.upcall(self, 'setInvalid', invalidControls);
61+ if (invalidControls.length === 1 &&
62+ invalidControls[0].name === '__result__') {
63+ self.valid = true;
64+ }
65+ },
66+
67
68 function valueChanged(self, control) {
69 Methanal.Widgets.LookupForm.upcall(
70@@ -1375,6 +1383,11 @@
71 // Trigger Lookup.onChange so the parent form refreshes validators.
72 self.widgetParent.onChange(control.node, self._initialisedOnce);
73
74+ if (!self.valid) {
75+ self.setResults([]);
76+ return;
77+ }
78+
79 // Don't trigger when the result input is changed or when there are
80 // validation errors.
81 if (control.name === '__result__') {

Subscribers

People subscribed via source and target branches

to all changes: