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

Possible Error in documentation for pull-request #46 #50

Open
lauterry opened this issue Feb 20, 2017 · 3 comments
Open

Possible Error in documentation for pull-request #46 #50

lauterry opened this issue Feb 20, 2017 · 3 comments

Comments

@lauterry
Copy link

lauterry commented Feb 20, 2017

Hi

Regarding this pull request #46

I expect the following code to work :

export const passwordFieldValidator = composeValidators(
	isRequired({
		id: 'error.password.required',
		description: 'Error message password required',
		defaultMessage: 'You must provide a password'
	}),
	hasLengthGreaterThan(5)(
		id: 'error.password.required',
		description: 'Error message password required',
		defaultMessage: 'You must provide a password'
	})
)('password');

But It doesn't and I got the Error message :

Error: Please provide a string or configuration object with a `field` or `message` property

However, in order to work, I have to put a field property like this :

export const passwordFieldValidator = composeValidators(
	isRequired({
		field: {
			id: 'error.password.required',
			description: 'Error message password required',
			defaultMessage: 'You must provide a password'
		}
	}),
	hasLengthGreaterThan(5)({
		field: {
			id: 'error.password.required',
			description: 'Error message password required',
			defaultMessage: 'You must provide a password'
		}
	})
)('password');

If this is the case, it seems that the example in the documentation is not correct here http://revalidate.jeremyfairbank.com/usage/createValidator.html.

In the current documentation the example code is :

const requiredName = isRequired({
  id: 'name',
  defaultMessage: 'Name is required',
});

whereas it should be :

const requiredName = isRequired({
   field : {
       id: 'name',
      defaultMessage: 'Name is required',
   }
});

Am I correct or did I miss something ?

Best regards

@Zagitta
Copy link
Contributor

Zagitta commented Feb 20, 2017

You're missing you must redefine all the validators you use to support i18n. Something like this:

export const format = (msg, fields={}) => (field) => ({field, msg, ...fields});
export const isRequired = createValidator(msg => value => {   
    if(valueMissing(value))
        return msg; 
},format(messages.isRequired));

@jfairbank
Copy link
Owner

Hi, @lauterry. This is definitely an error in the documentation that I must've missed. I'll fix the docs unless you want to open a PR.

@Zagitta I'm not sure your example would work in this case unless I'm missing something.

@gilbarbara
Copy link

@jfairbank It would be nice to update the docs! :)

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

No branches or pull requests

4 participants