【发布时间】:2018-10-27 16:59:18
【问题描述】:
我在我的应用中实现了 react-datepicker。
一切都很好,除了我想自定义日期选择器的输入字段并将其调整为我的其他自定义字段,如标题输入。
当我通过
更改日期选择器时customInput={<Input />}
字段,它的外观已更改,但我无法再选择日期(选择器不再工作)。
这是我的代码:
<DatePicker
customInput={<Input />}
dateFormat="DD.MM.YYYY"
selected=...
onChange=...
/>
有什么想法吗?
export namespace Input {
export interface Props {
onChange: (event: any) => void;
placeholder?: string;
value?: string | number;
isSecure?: any;
id?: string;
}
// ...
}
所以我通过以下方式添加了时钟事件:
export namespace Input {
export interface Props {
onChange: (event: any) => void;
placeholder?: string;
value?: string | number;
isSecure?: any;
id?: string;
onClick: (event: any) => void;
}
}
对吗?
组件代码:
export class Input extends React.Component<Input.Props, Input.State> {
public render() {
const controlClass = classNames(
[style.control]
);
const inputClass = classNames(
[style.input]
);
return (
<p className={controlClass} >
<input
id={this.props.id}
onChange={this.props.onChange}
className={inputClass}
type={this.props.isSecure ? "password" : "text"}
placeholder={this.props.placeholder}
value={this.props.value}
/>
</p>
);
}
}
【问题讨论】:
-
Input组件长什么样?很可能输入组件没有正确实现onChange事件。 -
export namespace Input { export interface Props { onChange: (event: any) => void;占位符?:字符串;值?:字符串 |数字; isSecure?:任何; id?:字符串; }
-
你可以edit你的问题在那里添加代码而不是评论。
-
完成:) 你能看穿吗?
标签: javascript reactjs datepicker