mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 20:18:03 +08:00
form增加trim,treeSelect增加maxLength/minLength
This commit is contained in:
parent
2568e39e42
commit
27c7620c3b
@ -51,6 +51,8 @@ interface TreeSelectorProps {
|
||||
rootValue?: any;
|
||||
cascade?: boolean;
|
||||
selfDisabledAffectChildren?: boolean;
|
||||
minLength?: number;
|
||||
maxLength?: number;
|
||||
}
|
||||
|
||||
interface TreeSelectorState {
|
||||
@ -292,6 +294,8 @@ export class TreeSelector extends React.Component<TreeSelectorProps, TreeSelecto
|
||||
classnames: cx,
|
||||
highlightTxt,
|
||||
data,
|
||||
maxLength,
|
||||
minLength
|
||||
} = this.props;
|
||||
|
||||
let childrenChecked = 0;
|
||||
@ -327,6 +331,13 @@ export class TreeSelector extends React.Component<TreeSelectorProps, TreeSelecto
|
||||
|
||||
let nodeDisabled = !!uncheckable || !!disabled || selfDisabled;
|
||||
|
||||
if (
|
||||
(maxLength && !selfChecked && this.state.value.length >= maxLength)
|
||||
|| (minLength && selfChecked && this.state.value.length <= minLength)
|
||||
) {
|
||||
nodeDisabled = true;
|
||||
}
|
||||
|
||||
const checkbox: JSX.Element | null = multiple ? (
|
||||
<label className={cx(`Checkbox Checkbox--checkbox Checkbox--sm`)}>
|
||||
<input
|
||||
|
@ -344,7 +344,9 @@ export default class TreeSelectControl extends React.Component<TreeSelectProps,
|
||||
classPrefix: ns,
|
||||
optionsPlaceholder,
|
||||
searchable,
|
||||
autoComplete
|
||||
autoComplete,
|
||||
maxLength,
|
||||
minLength
|
||||
} = this.props;
|
||||
|
||||
let filtedOptions = !isEffectiveApi(autoComplete) && searchable && this.state.inputValue ? this.filterOptions(options, this.state.inputValue) : options;
|
||||
@ -389,6 +391,8 @@ export default class TreeSelectControl extends React.Component<TreeSelectProps,
|
||||
hideRoot
|
||||
value={value || ''}
|
||||
nameField="label"
|
||||
maxLength={maxLength}
|
||||
minLength={minLength}
|
||||
/>
|
||||
</PopOver>
|
||||
</Overlay>
|
||||
|
@ -486,9 +486,14 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
target,
|
||||
env,
|
||||
onChange,
|
||||
clearPersistDataAfterSubmit
|
||||
clearPersistDataAfterSubmit,
|
||||
trim
|
||||
} = this.props;
|
||||
|
||||
if (trim) {
|
||||
store.trimValues();
|
||||
}
|
||||
|
||||
if (Array.isArray(action.required) && action.required.length) {
|
||||
return store
|
||||
.validateFields(action.required)
|
||||
@ -1029,7 +1034,7 @@ export class FormRenderer extends Form {
|
||||
}
|
||||
|
||||
const component = scoped.getComponentByName(name);
|
||||
component && component.receive && component && component.receive(values, subPath);
|
||||
component && component.receive && component.receive(values, subPath);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -180,6 +180,10 @@ export const FormStore = ServiceStore
|
||||
self.data = data;
|
||||
}
|
||||
|
||||
function trimValues() {
|
||||
self.items.forEach(item => item.trimValue());
|
||||
}
|
||||
|
||||
function syncOptions() {
|
||||
self.items.forEach(item => item.syncOptions());
|
||||
}
|
||||
@ -410,6 +414,7 @@ export const FormStore = ServiceStore
|
||||
setInited,
|
||||
setValues,
|
||||
setValueByName,
|
||||
trimValues,
|
||||
submit,
|
||||
validate,
|
||||
validateFields,
|
||||
|
@ -23,7 +23,8 @@ import findIndex = require('lodash/findIndex');
|
||||
import {
|
||||
isArrayChilrenModified,
|
||||
hasOwnProperty,
|
||||
isObject
|
||||
isObject,
|
||||
iterateChildren
|
||||
} from '../utils/helper';
|
||||
import {
|
||||
flattenTree
|
||||
@ -491,6 +492,11 @@ export const FormItemStore = types
|
||||
clearError();
|
||||
}
|
||||
|
||||
function trimValue() {
|
||||
let value = iterateChildren(self.value, (item:any) => typeof item === 'string' && item.trim());
|
||||
value && changeValue(value, false);
|
||||
}
|
||||
|
||||
return {
|
||||
config,
|
||||
changeValue,
|
||||
@ -502,7 +508,8 @@ export const FormItemStore = types
|
||||
loadOptions,
|
||||
syncOptions,
|
||||
setLoading,
|
||||
reset
|
||||
reset,
|
||||
trimValue
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -724,4 +724,18 @@ export function chainFunctions(...fns:Array<(...args:Array<any>) => void>):(...a
|
||||
return (...args:Array<any>) => {
|
||||
fns.forEach(fn => fn && fn(...args));
|
||||
}
|
||||
}
|
||||
|
||||
export function iterateChildren(value: any, fn: Function): any {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(item => iterateChildren(item, fn));
|
||||
}
|
||||
if (isObject(value)) {
|
||||
let tmpValue = Object.assign({}, value);
|
||||
Object.keys(tmpValue).forEach(key => {
|
||||
(tmpValue as {[propName: string]: any})[key] = iterateChildren((tmpValue as {[propName: string]: any})[key], fn);
|
||||
});
|
||||
return tmpValue;
|
||||
}
|
||||
return fn(value);
|
||||
}
|
Loading…
Reference in New Issue
Block a user