Skip to content

Commit

Permalink
fix(form): only pass locale string to flatpickr
Browse files Browse the repository at this point in the history
  • Loading branch information
anehx committed Mar 18, 2024
1 parent 3e064a5 commit 580371e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 50 deletions.
2 changes: 1 addition & 1 deletion packages/-ember-caluma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"ember-engines": "0.9.0",
"ember-engines-router-service": "0.5.1",
"ember-fetch": "8.1.2",
"ember-flatpickr": "7.1.0",
"ember-flatpickr": "8.0.0",
"ember-intl": "6.5.3",
"ember-load-initializers": "2.1.2",
"ember-math-helpers": "4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/distribution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ember-concurrency": "^4.0.1",
"ember-engines-router-service": "^0.5.1",
"ember-fetch": "^8.1.2",
"ember-flatpickr": "^7.1.0",
"ember-flatpickr": "^8.0.0",
"ember-intl": "^6.5.3",
"ember-svg-jar": "^2.4.9",
"ember-test-selectors": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/form-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"ember-concurrency": "^4.0.1",
"ember-engines-router-service": "^0.5.1",
"ember-fetch": "^8.1.2",
"ember-flatpickr": "^7.1.0",
"ember-flatpickr": "^8.0.0",
"ember-intl": "^6.5.3",
"ember-math-helpers": "^4.0.0",
"ember-power-select": "^7.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/form/addon/components/cf-field/input/date.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class="uk-input {{if @disabled 'uk-disabled'}}"
readonly={{@disabled}}
@disabled={{@disabled}}
@locale={{this.localeObject}}
@locale={{this.locale}}
@date={{or @field.answer.value null}}
@altFormat={{this.dateFormat}}
@altInput={{true}}
Expand Down
5 changes: 0 additions & 5 deletions packages/form/addon/components/cf-field/input/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import lang from "flatpickr/dist/l10n";
import { DateTime } from "luxon";

export default class CfFieldInputDateComponent extends Component {
Expand All @@ -15,10 +14,6 @@ export default class CfFieldInputDateComponent extends Component {
return this.intl.primaryLocale.split("-")[0];
}

get localeObject() {
return lang[this.locale];
}

get config() {
return getOwner(this).resolveRegistration("config:environment");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"ember-composable-helpers": "^5.0.0",
"ember-concurrency": "^4.0.1",
"ember-fetch": "^8.1.2",
"ember-flatpickr": "^7.1.0",
"ember-flatpickr": "^8.0.0",
"ember-in-viewport": "^4.1.0",
"ember-intl": "^6.5.3",
"ember-math-helpers": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fillIn, blur, render } from "@ember/test-helpers";
import { fillIn, blur, render, waitFor } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { setFlatpickrDate } from "ember-flatpickr/test-support/helpers";
import { setupIntl, setLocale } from "ember-intl/test-support";
Expand Down Expand Up @@ -51,17 +51,17 @@ module("Integration | Component | cf-field/input/date", function (hooks) {
hbs`<CfField::Input::Date @disabled={{true}} @field={{this.field}} />`,
);

await waitFor(".ember-flatpickr-input.input");

assert.dom(".ember-flatpickr-input.input").hasAttribute("type", "text");
assert.dom(".ember-flatpickr-input.input").hasValue("10.09.2021");
assert
.dom(".ember-flatpickr-input:not([type='hidden'])")
.hasAttribute("type", "text");
assert
.dom(".ember-flatpickr-input:not([type='hidden'])")
.hasValue("10.09.2021");
assert
.dom(".ember-flatpickr-input[type='hidden']")
.dom(".ember-flatpickr-input.flatpickr-input")
.hasAttribute("readonly");
assert.dom(".ember-flatpickr-input[type='hidden']").hasClass("uk-disabled");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("2021-09-10");
assert
.dom(".ember-flatpickr-input.flatpickr-input")
.hasClass("uk-disabled");
assert.dom(".ember-flatpickr-input.flatpickr-input").hasValue("2021-09-10");
});

test("it works on input", async function (assert) {
Expand All @@ -70,35 +70,29 @@ module("Integration | Component | cf-field/input/date", function (hooks) {
await render(hbs`<CfField::Input::Date @onSave={{fn (mut this.value)}} />`);

await setLocale("en-us");
await fillIn(".ember-flatpickr-input:not([type='hidden'])", "something");
await fillIn(".ember-flatpickr-input.input", "something");
await blur();
assert.strictEqual(this.value, null);
assert.dom(".ember-flatpickr-input:not([type='hidden'])").hasValue("");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("");
assert.dom(".ember-flatpickr-input.input").hasValue("");
assert.dom(".ember-flatpickr-input.flatpickr-input").hasValue("");

await fillIn(".ember-flatpickr-input:not([type='hidden'])", "1/30/2013");
await fillIn(".ember-flatpickr-input.input", "1/30/2013");
await blur();
assert.strictEqual(this.value, "2013-01-30");
assert
.dom(".ember-flatpickr-input:not([type='hidden'])")
.hasValue("01/30/2013");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("2013-01-30");
assert.dom(".ember-flatpickr-input.input").hasValue("01/30/2013");
assert.dom(".ember-flatpickr-input.flatpickr-input").hasValue("2013-01-30");

await setLocale("de-ch");
await fillIn(".ember-flatpickr-input:not([type='hidden'])", "20.2.2022");
await fillIn(".ember-flatpickr-input.input", "20.2.2022");
await blur();
assert.strictEqual(this.value, "2022-02-20");
assert
.dom(".ember-flatpickr-input:not([type='hidden'])")
.hasValue("20.02.2022");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("2022-02-20");
assert.dom(".ember-flatpickr-input.input").hasValue("20.02.2022");
assert.dom(".ember-flatpickr-input.flatpickr-input").hasValue("2022-02-20");

await fillIn(".ember-flatpickr-input:not([type='hidden'])", "25.03.2021");
await fillIn(".ember-flatpickr-input.input", "25.03.2021");
await blur();
assert.strictEqual(this.value, "2021-03-25");
assert
.dom(".ember-flatpickr-input:not([type='hidden'])")
.hasValue("25.03.2021");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("2021-03-25");
assert.dom(".ember-flatpickr-input.input").hasValue("25.03.2021");
assert.dom(".ember-flatpickr-input.flatpickr-input").hasValue("2021-03-25");
});
});
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 580371e

Please sign in to comment.