nicolaslopezj/simple-react-form

Validation in onSubmit event

ivansglazunov opened this issue · 4 comments

Accounts.LogInSchema.messages({
    email: "Email is not exists"
});
AutoForm.hooks({
  myForm: {
    onSubmit: function (insertDoc, updateDoc, currentDoc) {
      this.event.preventDefault();
      this.validationContext.addInvalidKeys([{ name: "email", type: "email" }]);
      this.done('error');
      return false;
    }
  }
});

Or how else to add custom check with onSubmit={} event?

Founded.

<Form
  schema={Schema}
  type="function"
  ref="myForm"
  onSubmit={() => this.refs.myForm.setErrorMessage('email', 'Email is not exists'); }
/>
</div>

However, it possible to do this with SimpleSchema messages?

If you can do a validation with simple-schema, it will show the error message for the field. https://github.com/aldeed/meteor-simple-schema/#custom-validation

How is about "Asynchronous Custom Validation on the Client"?
https://github.com/aldeed/meteor-simple-schema#asynchronous-custom-validation-on-the-client
Is it possible with srf package?

You can make async calls and then set the error in the state and pass it to the fields

<Field fieldName='name' errorMessage={this.state.errorMessage} type={Text} />