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

Autosave=true triggering validation immediately #238

Closed
todda00 opened this issue Mar 21, 2017 · 7 comments
Closed

Autosave=true triggering validation immediately #238

todda00 opened this issue Mar 21, 2017 · 7 comments
Assignees
Labels
Type: Bug Bug reports and their fixes

Comments

@todda00
Copy link
Contributor

todda00 commented Mar 21, 2017

If autosave={true}, the form is validated immediately.

If the autosave is enabled after it is rendered (like the uniforms.tools demo is) then validation does not occur until after the first change, but if its enabled at the time of form render, the validation occurs immediately.

I have tried multiple schemas, and allowed AutoForm to use default field components both with the same results.

Using bootstrap4, Simple Schema 2

@janowsiany
Copy link
Contributor

Hello there, thanks for reporting. This may be closely related with #204. Let me investigate this later today, ok?

@janowsiany janowsiany self-assigned this Mar 21, 2017
@janowsiany janowsiany added the Type: Bug Bug reports and their fixes label Mar 21, 2017
@todda00
Copy link
Contributor Author

todda00 commented Mar 21, 2017

Sure thing, no rush - I put a workaround in place which works by not setting autosave until onChange is triggered the first time:

const autosave = this.state[`autosave-${key}`] || false;
<AutoForm
  onSubmit={input => this.handleSaveShop({ input, uq, location })}
  schema={formSchema}
  model={shop}
  className="form-inline"
  onChange={() => this.setState({ [`autosave-${key}`]: true })}
  autosave={autosave}
>

@radekmie
Copy link
Contributor

@todda00 could you share an example of schema what behaves like this?

@todda00
Copy link
Contributor Author

todda00 commented Mar 21, 2017

This is the simpler of the 2 I tested it with:

export const schema = new SimpleSchema({
  _id: { type: String, regEx: SimpleSchema.RegEx.Id, optional: true },
  title: String,
  industry: String,
  sampleLink: { type: String, optional: true },
  introText: { type: String, optional: true },
  standardQuestions: { type: String, optional: true },
  minimumReimbursement: Number,
  cost: Number,
  published: {
    type: Boolean,
    defaultValue: false,
  },
});

@radekmie
Copy link
Contributor

radekmie commented Mar 21, 2017

Thank you. I'm guessing right now, but it's caused by defaultValue - I'll get to it soon.

EDIT 1: It's not.
EDIT 2: Making every field optional (or rendering a form with predefined values) works. Source.

@todda00
Copy link
Contributor Author

todda00 commented Mar 21, 2017

I had that thought as well, but I removed the defaultValue from the schema and it still validates immediately.

@radekmie
Copy link
Contributor

Do you know that moment, when you start debugging something and result in rewriting a part of the core functionality? No? We are not similar then. It's fixed now and will be released soon, but it's worth mentioning, that uniforms will be faster now. Like, really faster for bigger forms.

All tests are passing, I hope everything works...

@radekmie radekmie moved this to Closed in Open Source Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug reports and their fixes
Projects
Archived in project
Development

No branches or pull requests

3 participants