Skip to content

Commit b4a8743

Browse files
committed
Fix Cannot read property 'changed' of undefined error; fixes #961
1 parent ab57929 commit b4a8743

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

autoform-inputs.js

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -154,50 +154,57 @@ getInputData = function getInputData(defs, hash, value, label, formType) {
154154
return inputTypeContext;
155155
};
156156

157-
updateTrackedFieldValue = function updateTrackedFieldValue(template, fieldName) {
157+
function markChanged(template, fieldName) {
158+
// We always want to be sure to wait for DOM updates to
159+
// finish before we indicate that values have changed.
160+
// Using a value of 0 here did not work, but 100 seems to
161+
// work in testing. We'll need to keep an eye on this.
162+
// Not an ideal solution.
163+
setTimeout(function () {
164+
// Template or view may have disappeared while
165+
// we waited to run this
166+
if (template &&
167+
template.view &&
168+
template.view._domrange &&
169+
!template.view.isDestroyed) {
170+
171+
template.formValues[fieldName].changed();
172+
template.formValues[fieldName].requestInProgress = false;
158173

159-
if (template) {
160-
template.formValues = template.formValues || {};
161-
if (!template.formValues[fieldName]) {
162-
template.formValues[fieldName] = new Tracker.Dependency();
163-
}
164-
// In case we call updateTrackedFieldValue from multiple places at once,
165-
// call .changed() only once
166-
if (template.formValues[fieldName].requestInProgress) {
167-
return;
168174
}
169-
template.formValues[fieldName].requestInProgress = true;
170-
}
175+
}, 100);
176+
}
171177

172-
function markChanged() {
173-
// We always want to be sure to wait for DOM updates to
174-
// finish before we indicate that values have changed.
175-
// Using a value of 0 here did not work, but 100 seems to
176-
// work in testing. We'll need to keep an eye on this.
177-
// Not an ideal solution.
178-
setTimeout(function () {
179-
// Template or view may have disappeared while
180-
// we waited to run this
181-
if (template &&
182-
template.view &&
183-
template.view._domrange &&
184-
!template.view.isDestroyed) {
185-
186-
template.formValues[fieldName].changed();
187-
template.formValues[fieldName].requestInProgress = false;
178+
updateTrackedFieldValue = function updateTrackedFieldValue(template, fieldName) {
179+
if (!template) {
180+
return;
181+
}
188182

189-
}
190-
}, 100);
183+
template.formValues = template.formValues || {};
184+
if (!template.formValues[fieldName]) {
185+
template.formValues[fieldName] = new Tracker.Dependency();
186+
}
187+
// In case we call updateTrackedFieldValue from multiple places at once,
188+
// call .changed() only once
189+
if (template.formValues[fieldName].requestInProgress) {
190+
return;
191191
}
192+
template.formValues[fieldName].requestInProgress = true;
192193

193-
markChanged();
194+
markChanged(template, fieldName);
194195

195196
// To properly handle array fields, we'll mark the ancestors as changed, too
196197
// XXX Might be a more elegant way to handle this
197198
var dotPos = fieldName.lastIndexOf('.');
198199
while (dotPos !== -1) {
199200
fieldName = fieldName.slice(0, dotPos);
200-
markChanged();
201+
202+
if (!template.formValues[fieldName]) {
203+
template.formValues[fieldName] = new Tracker.Dependency();
204+
}
205+
206+
markChanged(template, fieldName);
207+
201208
dotPos = fieldName.lastIndexOf('.');
202209
}
203210
};

0 commit comments

Comments
 (0)