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

feat: date picker custom format #2276

Merged

Conversation

XcrossD
Copy link
Contributor

@XcrossD XcrossD commented May 20, 2020

First of all, thank you for your contribution! 😄

New feature please send pull request to feature branch, and rest to master branch. Pull request will be merged after one of collaborators approve. Please makes sure that these form are filled before submitting your pull request, thank you!

[中文版模板 / Chinese template]

This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Branch merge
  • Other (about what?)

What's the background?

  1. Describe the source of requirement.

I'm trying to implement lunar calendar with datepicker, but obviously moment does not support the formatting of lunar calendar dates. It would be great to accept a function to render custom date strings in the input, instead of relying on moment.format().

  1. Resolve what problem.

DatePicker only allows momentjs formatting.

  1. Related issue link.

#2236

API Realization (Optional if not new feature)

  1. Basic thought of solution and other optional proposal.

I dug around and found out that format is related to formatDate function, so I added support for function to it.

  1. List final API realization and usage sample.
<template>
  <a-date-picker
    v-model="value"
    :format="customFormat"
  >

  </a-date-picker>
</template>

<script>
  export default {
    data() {
      return {
        value: null,
      }
    },
    methods: {
      customFormat(value) {
        return getLunarDateString(value); // custom implementation to get lunar calendar date
      }
    }
  };
</script>

An error will be thrown if the function doesn't return a string to ensure there is a value.

  1. GIF or snapshot should be provided if includes UI/interactive modification.

What's the effect? (Optional if not new feature)

  1. Does this PR affect user? Which part will be affected?

DatePicker

  1. What will say in changelog?

Allow a function to be passed into the format property of DatePicker for display string customization.

  1. Does this PR contains potential break change or other risk?

This should not be a breaking change.

Changelog description (Optional if not new feature)

  1. English description

Allow a function to be passed into the format property of DatePicker for display string customization.

  1. Chinese description (optional)

Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Additional Plan? (Optional if not new feature)

  1. I don't know how to get PropType to work with functions. I made some changes to PropType, but it still shows the vue warning that format expects only string and array.
  2. Probably a better way to handle the passed in function not returning a string is to have it fall back to the default format the DatePicker is using, but I'm not sure how to do that.

If this PR related with other PR or following info. You can type here.

@XcrossD XcrossD changed the title Feat date picker custom format feat: date picker custom format May 20, 2020
@tangjinzhou tangjinzhou merged commit 61eeb14 into vueComponent:master Jul 1, 2020
@github-actions
Copy link

github-actions bot commented Jul 2, 2021

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants