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

Formatter Function #841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Formatter Function #841

wants to merge 1 commit into from

Conversation

iomariani
Copy link
Contributor

This change adds the ability to format the value displayed on the slider through the function "formatter", instead of only appending to it with the prop "text-fixed".

I needed this functionality on a project so I could use the slider as a slider range for time HH:mm, thought this would be useful to someone else as well.

Example hours:minutes

<template>
  <div>
    <vs-slider :min="0" :max="24" :step="0.5" stepDecimals :formatter="timingFormatter" v-model="timing" />

    <p>{{ formatter(timing[0]) }} - {{formatter(timing[1])}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      timing: [0, 24]
    }
  },
  methods: {
    timingFormatter(value) {
      const hours = parseInt(value)
      const minutes = Math.round((value - hours) * 60)

      if (hours === 24) {
        return '23:59'
      } else {
        return hours.toString().padStart(2, '0') + ':' + minutes.toString().padStart(2, '0')
      }
    }
  }
}
</script>

image

Add the ability to format the value displayed on the slider through the function "formatter"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant