mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 05:18:34 +08:00
优化autoFill
This commit is contained in:
parent
ee92008e01
commit
a022591844
@ -19,8 +19,6 @@ import Checkbox from './Checkbox';
|
||||
import {value2array, OptionProps, Option} from './Checkboxes';
|
||||
import chunk = require('lodash/chunk');
|
||||
import {ClassNamesFn, themeable} from '../theme';
|
||||
import {isEmpty} from '../utils/helper';
|
||||
import {dataMapping} from '../utils/tpl-builtin';
|
||||
|
||||
interface RadioProps extends OptionProps {
|
||||
id?: string;
|
||||
@ -52,14 +50,10 @@ export class Radios extends React.Component<RadioProps, any> {
|
||||
const {
|
||||
value,
|
||||
onChange,
|
||||
joinValues,
|
||||
extractValue,
|
||||
valueField,
|
||||
clearable,
|
||||
delimiter,
|
||||
options,
|
||||
autoFill,
|
||||
onBulkChange
|
||||
options
|
||||
} = this.props;
|
||||
|
||||
let valueArray = value2array(value, {
|
||||
@ -78,17 +72,6 @@ export class Radios extends React.Component<RadioProps, any> {
|
||||
|
||||
let newValue = valueArray[0];
|
||||
|
||||
const sendTo = autoFill && !isEmpty(autoFill) && dataMapping(autoFill, newValue as Option);
|
||||
sendTo && onBulkChange && onBulkChange(sendTo);
|
||||
|
||||
if (newValue && (joinValues || extractValue)) {
|
||||
newValue = newValue[valueField || 'value'];
|
||||
}
|
||||
|
||||
// if (joinValues && newValue) {
|
||||
// newValue = newValue[valueField || 'value'];
|
||||
// }
|
||||
|
||||
onChange && onChange(newValue);
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,6 @@ import {
|
||||
import cx from 'classnames';
|
||||
import Checkbox from '../../components/Checkbox';
|
||||
import chunk = require('lodash/chunk');
|
||||
import {autobind, isEmpty} from '../../utils/helper';
|
||||
import {dataMapping} from '../../utils/tpl-builtin';
|
||||
|
||||
export interface CheckboxesProps extends OptionsControlProps {
|
||||
placeholder?: any;
|
||||
@ -33,20 +31,6 @@ export default class CheckboxesControl extends React.Component<CheckboxesProps,
|
||||
defaultCheckAll && onToggleAll();
|
||||
}
|
||||
|
||||
@autobind
|
||||
handleToggle(option: Option) {
|
||||
const {
|
||||
onToggle,
|
||||
multiple,
|
||||
autoFill,
|
||||
onBulkChange
|
||||
} = this.props;
|
||||
|
||||
const sendTo = !multiple && autoFill && !isEmpty(autoFill) && dataMapping(autoFill, option as Option);
|
||||
sendTo && onBulkChange(sendTo);
|
||||
onToggle(option);
|
||||
}
|
||||
|
||||
renderGroup(option:Option, index:number) {
|
||||
const {
|
||||
classnames: cx
|
||||
@ -82,7 +66,7 @@ export default class CheckboxesControl extends React.Component<CheckboxesProps,
|
||||
<Checkbox
|
||||
className={itemClassName}
|
||||
key={index}
|
||||
onChange={() => this.handleToggle(option)}
|
||||
onChange={() => onToggle(option)}
|
||||
checked={!!~selectedOptions.indexOf(option)}
|
||||
disabled={disabled || option.disabled}
|
||||
inline={inline}
|
||||
|
@ -152,7 +152,7 @@ export default class PickerControl extends React.PureComponent<PickerProps, any>
|
||||
});
|
||||
|
||||
additionalOptions.length && setOptions(options.concat(additionalOptions));
|
||||
const sendTo = !multiple && !joinValues && !extractValue && autoFill && !isEmpty(autoFill) && dataMapping(autoFill, value as Option);
|
||||
const sendTo = !multiple && autoFill && !isEmpty(autoFill) && dataMapping(autoFill, value as Option);
|
||||
sendTo && onBulkChange(sendTo);
|
||||
onChange(value);
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import {
|
||||
OptionsControlProps,
|
||||
Option
|
||||
} from './Options';
|
||||
import {autobind, isEmpty} from '../../utils/helper';
|
||||
import {dataMapping} from '../../utils/tpl-builtin';
|
||||
|
||||
export interface RadiosProps extends OptionsControlProps {
|
||||
placeholder?: any;
|
||||
@ -21,6 +23,27 @@ export default class RadiosControl extends React.Component<RadiosProps, any> {
|
||||
columnsCount: 1
|
||||
}
|
||||
|
||||
@autobind
|
||||
handleChange(option: Option) {
|
||||
const {
|
||||
joinValues,
|
||||
extractValue,
|
||||
valueField,
|
||||
onChange,
|
||||
autoFill,
|
||||
onBulkChange
|
||||
} = this.props;
|
||||
|
||||
const sendTo = autoFill && !isEmpty(autoFill) && dataMapping(autoFill, option);
|
||||
sendTo && onBulkChange && onBulkChange(sendTo);
|
||||
|
||||
if (option && (joinValues || extractValue)) {
|
||||
option = option[valueField || 'value'];
|
||||
}
|
||||
|
||||
onChange && onChange(option);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
className,
|
||||
@ -37,9 +60,7 @@ export default class RadiosControl extends React.Component<RadiosProps, any> {
|
||||
formMode,
|
||||
columnsCount,
|
||||
classPrefix,
|
||||
itemClassName,
|
||||
autoFill,
|
||||
onBulkChange
|
||||
itemClassName
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
@ -48,9 +69,7 @@ export default class RadiosControl extends React.Component<RadiosProps, any> {
|
||||
className={cx(`${ns}RadiosControl`, className)}
|
||||
value={(typeof value === 'undefined' || value === null) ? '' : value}
|
||||
disabled={disabled}
|
||||
autoFill={autoFill}
|
||||
onBulkChange={onBulkChange}
|
||||
onChange={onChange}
|
||||
onChange={this.handleChange}
|
||||
joinValues={joinValues}
|
||||
extractValue={extractValue}
|
||||
delimiter={delimiter}
|
||||
|
Loading…
Reference in New Issue
Block a user