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

Prevent validation when schema has changed and form is not submitted #82

Closed
macrozone opened this issue Jul 21, 2016 · 4 comments
Closed
Assignees
Labels
Type: Bug Bug reports and their fixes

Comments

@macrozone
Copy link
Contributor

validate=onChangeAfterSubmit or validate=onSubmit should prevent validation unless the user has submitted the form for the first time.

If you update the schema, this option is ignored and the form is validated.

Updating the schema is valid, e.g. if you have options from a collection that you define on the schema or if you translate the schema.

I'll check if I can do a PR.

@macrozone
Copy link
Contributor Author

macrozone commented Jul 21, 2016

I think in ValidatedForm.componentWillReceiveProps

the same logic as in onChange should apply:

if (this.props.validate === 'onChange' ||
            this.props.validate === 'onChangeAfterSubmit' && this.state.validate) {
            this.onValidate(key, value);
        }

but componentWillReceiveProps does also sets state.validated and i don't know why yet, can you guys help?

@radekmie radekmie added the Type: Bug Bug reports and their fixes label Jul 21, 2016
@radekmie radekmie self-assigned this Jul 21, 2016
@radekmie
Copy link
Contributor

Yes, you are completely right @macrozone - just wrap this.onValidate in correct if (that from onChange). Do you want to create a PR for that?

@macrozone
Copy link
Contributor Author

macrozone commented Jul 27, 2016

YOU - ARE - AWESOME!

many thanks @radekmie ! Works like a charm ___

Btw. I created i18n_service for mantra that wraps meteor-universe-i18n and provides some convenience functions for mantra-apps. It's still rough, but works perferctly so far and i like to share:

https://gist.github.com/macrozone/f1ab1bf6f205f5bfb7518bac0d2854d5

It's meant to be initalized in the context in mantra app.

It has a function translateSchema, that translates a simpleSchema. It automatically sets labels by it's field name and the given namespace. It also defines a default universe.transform-function that can translate allowedValues.

It's meant to be used in a container:


export const composer = ({context}, onData) => {
  const { SimpleSchema, i18n } = context();
    const registerSchema = i18n.translateSchema(
      new SimpleSchema({
         email: {
           type: String
        },
        password: {
           type: String
        },
        language: {
            type: String,
            allowedValues: [ 'de', 'fr', 'it', 'en']
        }
      } ]), 'register'
    );
    onData(null, {registerSchema });
};

Then in your locale-yamls:

register:
  email: Your email
  password: Your password
  language:
     label: Your preffered language
     de: German
     fr: French
     it: Italian
     en: English

Without this PR here, the form would validate on every language change. Now you can change locale even in the middle of filling out a form :-)

Maybe we can integrate something similar in universe-i18n or release a npm package for this (meteor dependencies will be injected)

@radekmie
Copy link
Contributor

Wow, just wow!
I haven't played a lot with mantra yet, but translating form during filling is a great feature!

And as to i18n - if you like, go ahead, create an PR - we'll see, if it makes sense to create a separate package. Looking forward your progress!

@Monteth Monteth added this to Closed in Open Source (migrated) Jun 24, 2021
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

2 participants