Skip to content

Commit

Permalink
Merge pull request #35 from XavierOlland/master
Browse files Browse the repository at this point in the history
Fix for french message ;)
  • Loading branch information
perscrew authored Oct 25, 2019
2 parents 4cd370d + d0c5b85 commit 8d2c522
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ You can override this file via the component React props :
```js
const messages = {
en: {numbers: "error on numbers !"},
fr: {numbers: "erreur sur numbers !"}
fr: {numbers: "erreur sur les nombres !"}
};

<FormTest messages={messages} />
Expand Down
2 changes: 1 addition & 1 deletion defaultRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const defaultRules = {
minlength(length, value) {
if (length === void(0)) {
throw 'ERROR: It is not a valid length, checkout your minlength settings.';
} else if(value.length > length) {
} else if(value.length >= length) {
return true;
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class ValidationComponent extends Component {

// Method to check rules on a spefific field
_checkRules(fieldName, rules, value) {
if (!value && !rules.required ) {
if (!value && !rules.required ) {
return; // if value is empty AND its not required by the rules, no need to check any other rules
}
for (const key of Object.keys(rules)) {
Expand All @@ -64,6 +64,7 @@ export default class ValidationComponent extends Component {
// ex:
// [{ fieldName: "name", messages: ["The field name is required."] }]
_addError(fieldName, rule, value, isFn) {
value = rule == 'minlength'? value-1 : value;
const errMsg = this.messages[this.deviceLocale][rule].replace("{0}", fieldName).replace("{1}", value);
let [error] = this.errors.filter(err => err.fieldName === fieldName);
// error already exists
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('ValidationComponent:', () => {
it('messages props should be updated', () => {
const messages = {
en: {numbers: "error on numbers !"},
fr: {numbers: "erreur sur numbers !"}
fr: {numbers: "erreur sur les nombres !"}
};
const wrapper = shallow(<FormTest messages={messages} />);
const formTest = wrapper.instance();
Expand Down

0 comments on commit 8d2c522

Please sign in to comment.