Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

Fix translation validation #180

Merged
merged 2 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "focus-graph",
"version": "3.0.0",
"version": "3.1.0-rc1",
"description": "Form, data behaviours",
"main": "src/index.js",
"author": "FOCUS <focus@kleegroup.com>",
Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import isUndefined from 'lodash/isUndefined';
import isNaN from 'lodash/isNaN';
import isNumber from 'lodash/isNumber';
import isString from 'lodash/isString';

import i18n from 'i18next';
//Dependency

const translate = (str, params) => `${str}`;
const translate = (str, params) => `${i18n.t(str)}`;
const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;


Expand Down
19 changes: 5 additions & 14 deletions src/middlewares/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ import identity from 'lodash/identity';
import {INPUT_CHANGE, INPUT_BLUR, INPUT_BLUR_LIST,inputError, inputErrorList, inputChangeError, inputErrorChangeList} from '../actions/input';
import {CREATE_FORM, VALIDATE_FORM, SYNC_FORMS_ENTITY, SYNC_FORM_ENTITIES, setFormToSaving} from '../actions/form';
import {PENDING} from '../actions/entity-actions-builder';
import find from 'lodash/find';
import get from 'lodash/get';
import isUndefined from 'lodash/isUndefined';
import isNull from 'lodash/isNull';
import isEmpty from 'lodash/isEmpty';
import mapKeys from 'lodash/mapKeys';
import isArray from 'lodash/isArray';
import isString from 'lodash/isString';
import omit from 'lodash/omit';
import map from 'lodash/map';
import {find, get, isUndefined, isNull, isEmpty, mapKeys, isArray, isString, omit,map} from 'lodash';
import validate from './validate';
/**
* Default field formatter. Defaults to the identity function
Expand All @@ -25,7 +16,7 @@ const MIDDLEWARES_FORM_VALIDATION = 'MIDDLEWARES_FORM_VALIDATION';

// THIS IS A MOCK FUNCTION THAT MUST BE REPLACED BY THE FOCUS CORE VALIDATION
// TODO : replace this with the focus core function
export const __fake_focus_core_validation_function__ = (isRequired = false, validators = [], name, rawValue) => {
export const validationByDomain = (isRequired = false, validators = [], name, rawValue) => {

const validationResult = validate({name, value: rawValue}, validators);
const isValid = validationResult.isValid;
Expand Down Expand Up @@ -201,7 +192,7 @@ export const validateGlobal = (definitions, domains , formKey, entityPath, field
if(!domain){
throw new Error(`${MIDDLEWARES_FIELD_VALIDATION}: Your field ${fieldName} in the entity ${entityPath} don't have a domain, you may have an array field which have a **redirect** property in it.`)
}
validationResult = __fake_focus_core_validation_function__(isRequired, domain.validators, fieldName, value);
validationResult = validationByDomain(isRequired, domain.validators, fieldName, value);
}else {
validationResult = isRequired ? {isValid: false} : {isValid: true};
}
Expand All @@ -227,7 +218,7 @@ export const validateFieldForList = (definitions, domain, propertyNameLine, form
// if(value === 1) throw new Error(JSON.stringify({ domain, propertyNameLine, formKey, value, index, entityPath, fieldNameList}))
let validationResult= {};
const {isRequired} = get(definitions, propertyNameLine);
validationResult = __fake_focus_core_validation_function__(isRequired, domain.validators, propertyNameLine, value);
validationResult = validationByDomain(isRequired, domain.validators, propertyNameLine, value);
//if(value === 1) throw new Error(JSON.stringify(validationResult));
if (!validationResult.isValid ){
if(onChange ) dispatch(inputErrorChangeList(formKey, fieldNameList , entityPath, validationResult.error, propertyNameLine , index));
Expand Down Expand Up @@ -260,7 +251,7 @@ export const validateFieldArray = (definitions, domains, formKey, entityPath, fi
const definitionRedirect = get(definitions, `${redirect}.${propertyNameLine}`);
const isRequired = definitionRedirect.isRequired;
const domain = domains[definitionRedirect.domain];
validationResult = __fake_focus_core_validation_function__(isRequired, domain.validators, propertyNameLine, value);
validationResult = validationByDomain(isRequired, domain.validators, propertyNameLine, value);
}else {
throw new Error(`${MIDDLEWARES_FIELD_VALIDATION} : You must provide a "redirect" defintions to your list field : ${fieldNameList}`)
}
Expand Down