Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Errors not showing for sub schemas #359

Open
lynchem opened this issue Feb 20, 2020 · 0 comments · May be fixed by #360 or #434
Open

Validation Errors not showing for sub schemas #359

lynchem opened this issue Feb 20, 2020 · 0 comments · May be fixed by #360 or #434

Comments

@lynchem
Copy link

lynchem commented Feb 20, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant