Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker只选择年份,设置了mode=year,但是无法触发onChange #14017

Closed
zhangyanling77 opened this issue Dec 29, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@zhangyanling77
Copy link

commented Dec 29, 2018

The issue which is not created via http://new-issue.ant.design will be closed immediately.


注意:不是用 http://new-issue.ant.design 创建的 issue 会被立即关闭。

@ant-design-bot

This comment has been minimized.

Copy link

commented Dec 29, 2018

Hello @zhangyanling77, your issue has been closed because it does not conform to our issue requirements. Please use the Issue Helper to create an issue, thank you!

你好 @zhangyanling77,为了能够进行高效沟通,我们对 issue 有一定的格式要求,你的 issue 因为不符合要求而被自动关闭。你可以通过 issue 助手 来创建 issue 以方便我们定位错误。谢谢配合!

@Aladingding

This comment has been minimized.

Copy link

commented Mar 29, 2019

<LocaleProvider locale={zhCN}> { getFieldDecorator(field)( <DatePicker style={ style } placeholder={ placeholder || '请选择年份' } locale={ zhCN } // value={ this.state.time } open={ this.state.yearStartShow } mode='year' format='YYYY' // onChange={ this.handleChange } onOpenChange={ this.handleOpenChange.bind(this,'yearStart') } onPanelChange={ this.handlePanelChange.bind(this,'yearStart') } /> ) } </LocaleProvider>

do like this ,you will fix this bug, use onOpenChange and onPanelChange (maybe you need onFocus)

tks, 一江西流 关于antd 日期组件只选择年份,设置mode=year无法获取value的解决办法

四个方法并用一定能完美实现你的需求,哈哈哈,官方说,你既然都单选了,为什么不用下拉框,说的好有道理,我竟无言以对

@zongzi531

This comment has been minimized.

Copy link
Contributor

commented Apr 10, 2019

感谢 @Aladingding 的文章,@zhangyanling77 你们可以尝试这样解决问题:

class Demo extends Component {
  hankPicker = null
  hankYearChange = v => {
    // 更新 v
    // 强制关闭补丁
    this.hankPicker.picker.setState({ open: false });
  }
  render() {
    return (
      <DatePicker
        ref={ref => (this.hankPicker = ref)}
        onPanelChange={this.hankYearChange}
        mode="year"
        format="YYYY" />
    )
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.