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

Changing the config.locale option doesn't update the locale used #77

Closed
ghost opened this issue Apr 25, 2018 · 9 comments
Closed

Changing the config.locale option doesn't update the locale used #77

ghost opened this issue Apr 25, 2018 · 9 comments
Assignees

Comments

@ghost
Copy link

ghost commented Apr 25, 2018

I'm submitting a ...

[x] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 4.4.4
  • Vue.js version : 2.5.16
  • This package version : 7.0.1

Current behavior
Changing the config.locale option doesn't update the locale used in the config watcher.

I have got it to work with adding the following after this.fp.set(safeConfig):

this.fp.l10n = safeConfig.locale
this.fp.redraw()
@ankurk91
Copy link
Owner

@renzo-s
Can you setup a jsfiddle?

@ghost
Copy link
Author

ghost commented Apr 25, 2018

Not at the moment,

but the setup is simple

<template>
  <flat-pickr config="config" />
</template>

<script>
import { Dutch } from 'flatpickr/dist/l10n/nl.js'
import { english } from 'flatpickr/dist/l10n/default.js'

const langs = {
    en: english,
    nl: Object.assign({}, english, Dutch)
}

// ... vue inst with the data

methods() {
  setNL() {
     this.config.locale = langs['nl']
  }
  setEN() {
     this.config.locale = langs['en']
  }
}
</script>

And trigger the methods with a button or something

@ankurk91
Copy link
Owner

Ok, i will check.

@ankurk91 ankurk91 self-assigned this Apr 25, 2018
@ghost
Copy link
Author

ghost commented Apr 25, 2018

Quick fix we opted for was moving the mounted() contents to an init method and in de the config watcher call

this.fp.destroy()
this.fp = null
this.init()

This is quick and dirty but seems like the only way to also update the input value with the correct altFormat.

Hope this can be a nice enhancement in the future, or some help for others trying to implement l10n switching.

Thanks for the quick replies

@ankurk91
Copy link
Owner

@renzo-s
How good if parent flatpickr library handles this automatically for us?

@ghost
Copy link
Author

ghost commented Apr 25, 2018

😄even better. Have not investigated the lib enough to open a ticket though

@ankurk91
Copy link
Owner

ankurk91 commented Apr 28, 2018

Flatpickr does support changing locale dynamically.
https://github.com/flatpickr/flatpickr/blob/aa35684adc2cde8037776dfd583e1c74987db35b/src/index.ts#L2104-L2119

We need to figure out a way to implement in this vue component.

flatpickrInstance.set('locale', importedLocaleObjectGoesHere)

ankurk91 added a commit that referenced this issue Apr 28, 2018
@ankurk91
Copy link
Owner

@renzo-s
Finally I made it, check the commit above, i will release this after more testing.

ankurk91 added a commit that referenced this issue Apr 29, 2018
@ankurk91
Copy link
Owner

ankurk91 commented May 5, 2018

Fixed in v7.0.2

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

No branches or pull requests

1 participant