Description
I've been trying to figure out why validation errors are not shown reactively (they are detected) and I think the error is coming from simple schema's tracker integration with autoform. This is from a debugging session and I've not been able to verify by running a local copy so apologies if it's incorrect.
As a simple example, consider:
subSchema = {
bar: {type: String}
}
mainSchema = {
foo: {type: subSchema}
}
Assuming mainSchema
is the schema on the form but bar
is empty, bar
should set the class has-error
and set the help-block
. The problem I believe is that the code in ValidationContext
does not trigger the tracker dependency to change.
ValidationContext._schemaKeys = ["foo"];
So when markKeyChanged is called with "foo.bar" , hasOwnProperty will return false and not trigger a change.
This is the code:
export default class ValidationContext {
constructor(ss) {
this._simpleSchema = ss;
this._schema = ss.schema();
this._schemaKeys = Object.keys(this._schema);
this._validationErrors = [];
// Set up validation dependencies
this._deps = {};
const { tracker } = ss._constructorOptions;
if (tracker) {
this._depsAny = new tracker.Dependency();
this._schemaKeys.forEach((key) => {
this._deps[key] = new tracker.Dependency();
});
}
}
_markKeyChanged(key) {
const genericKey = MongoObject.makeKeyGeneric(key);
if (this._deps.hasOwnProperty(genericKey)) this._deps[genericKey].changed();
}
I'd create a PR but I'm strugling to actually install a local version of simpl-schema to be able to test my change first.
--------Edit---------
So from some local testing it appears the issue is more to do with adding the tracker dependency for each sub schema key so that later marKeyChanged can find it. I have a fix created and will try get a PR created.