I’m using a large nested schema, with children schemas within other schemas. Occasionally I need to access a value from a parent schema to use in an autoValue or autoform, to make things more readable to our users. I’m using the exact same schema tree for both insert and updates, with minimal controls for autoform in the template. specialTextA and specialTextV are entries from the parent schema. The parent schema includes an element of the type:[childSchema]
. Note: I initially coded this with || statements (short circuit evaluation on the if (typeof)
statements and the var =
. Converted that to longhand to see if I could beat the error. Same error occurs, sigh.
Sample Code, from the child schema
childSchemaText: {
type: String,
optional: true,
autoValue: function() {
var valueA = "";
var valueB = "";
// the next line generates an Uncaught TypeError: Cannot read property 'insertDoc' of null
if (typeof AutoForm.getFormValues().insertDoc.specialTextA !== 'undefined') { <-- console error points here
valueA= AutoForm.getFormValues().insertDoc.specialTextA;
}
if (typeof AutoForm.getFormValues().updateDoc.specialTextA !== 'undefined') {
valueA = AutoForm.getFormValues().updateDoc.specialTextA;
}
if (typeof AutoForm.getFormValues().insertDoc.specialTextB !== 'undefined') {
valueB = AutoForm.getFormValues().insertDoc.specialTextB;
}
if (typeof AutoForm.getFormValues().updateDoc.specialTextB !== 'undefined') {
valueB = AutoForm.getFormValues().updateDoc.specialTextB;
}
console.log("interim content from within childSchema.childSchemaText: ", valueA, valueB);
return "Reminder: check out " + valueA +", and also " + valueB;
},
},
Chrome browser console, after I entered Hamburger Shop and Tonys Pizza manually on the autoform.
interim content from within childSchema.childSchemaText: Hamburger Shop Tonys Pizza
Uncaught TypeError: Cannot read property 'insertDoc' of null
That last console error refers to the file that holds the child schema and the line number points to the first occurance of if(typeof AutoForm.... )
as shown above…
What’s happening here? Why is this working (per the console output) but not working (as I’m seeing an error message, and no “Reminder” message pasted into the desired output field on the form)?