react-drip-form
supports to the error message i18n.
You can deal with just one line using setLocale()
of drip-form-validator.
For locales that do not exist in drip-form-validator
, you can also define them with defineLocale()
.
Labels and other components are not supported. I think yahoo/react-intl is useful!
{}
import React from 'react';
import { dripForm, Validator } from 'react-drip-form';
import { Input, Textarea } from 'react-drip-form-components';
import 'drip-form-validator/lib/locale/ja';
Validator.setLocale('ja')
const I18nForm = dripForm({
validations: {
email: {
required: true,
email: true,
},
message: {
required: true,
},
},
})(({
handlers,
meta: { invalid, pristine },
}) => (
<form onSubmit={handlers.onSubmit}>
<div>
<label htmlFor="email">送信先</label>
<Input
id="email"
type="email"
name="email"
label="送信先"
/>
</div>
<div>
<label htmlFor="message">メッセージ</label>
<Textarea
id="message"
name="message"
label="メッセージ"
/>
</div>
<Button
primary
onClick={handlers.onSubmit}
disabled={invalid || pristine}
>
送信
</Button>
</form>
));