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 · 4 comments
Labels

Comments

@zhangyanling77
Copy link
Contributor

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
Copy link
Contributor

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 以方便我们定位错误。谢谢配合!

@Fujitomy
Copy link

<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
Copy link
Contributor

感谢 @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" />
    )
  }
}

@KaivOU
Copy link

KaivOU commented May 31, 2019

@zachguo 你把@aladingding 的文章那种方法简化了,同时也解决了他哪种方法的:点击二次弹出弹窗的bug,这句this.hankPicker.picker.setState({ open: false }); that's good thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants