reduxFormReducer.js
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as types from '../constants/ActionTypes';
import {reducer as formReducer} from 'redux-form';
const errorMsg=(state, action)=>{
switch(action.type) {
case types.CHANGE_ERROR:
return Object.assign({}, state, {
_error: action.error
});
case 'redux-form/CHANGE':
return Object.assign({}, state, {
_error: null,
[action.field]:{
value:action.value.replace?action.value.replace(/(^\s*)|(\s*$)/g,''):action.value
}
});
default:
return state;
}
}
const dynamiceErrorMsg=(state, action)=>{
switch(action.type) {
case types.DYNAMIC_FORM_CHANGE_ERROR:
return Object.assign({}, state, {
errors: {name:'创建数据已存在'}
});
case 'redux-form/CHANGE':
return Object.assign({}, state, {
_error: null,
[action.field]:{
value:action.value.replace?action.value.replace(/(^\s*)|(\s*$)/g,''):action.value
}
});
default:
return state;
}
}
export default formReducer.plugin({
announcementForm:errorMsg,
loginForm: errorMsg,
registerForm:errorMsg,
// dynamic_form_approve:dynamiceErrorMsg,
dynamic_form:dynamiceErrorMsg
})