Skip to content

Commit

Permalink
fixing old embroiderer packages, working on implementing internationa…
Browse files Browse the repository at this point in the history
…l number formatting
  • Loading branch information
ErvinSabic committed Jan 18, 2025
1 parent c738342 commit a12a7b7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/ember-headless-form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"babel-eslint": "^10.1.0",
"ember-async-data": "^1.0.3",
"ember-modifier": "^4.1.0",
"intl-number-parser": "^1.0.5",
"tracked-built-ins": "^3.1.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export interface HeadlessFormControlInputComponentSignature {
*/
type?: InputType;

/**
* Some inputs are specific to locales, like numbers. This
*
*
*
*/
locale?: string

// the following are private arguments curried by the component helper, so users will never have to use those

/*
Expand Down Expand Up @@ -106,10 +114,18 @@ export default class HeadlessFormControlInputComponent extends Component<Headles
@action
handleInput(e: Event | InputEvent): void {
assert('Expected HTMLInputElement', e.target instanceof HTMLInputElement);
this.args.setValue(
this.type === 'number' ? parseFloat(e.target.value) : e.target.value
);
this.args.setValue(e.target.value);
}

@action
handleUnfocus(e: Event | InputEvent): void {
assert('Expected HTMLInputElement', e.target instanceof HTMLInputElement);

if(this.type === "number"){
this.args.setValue(parseFloat(e.target.value));
}
}

<template>
<input
name={{@name}}
Expand All @@ -120,6 +136,7 @@ export default class HeadlessFormControlInputComponent extends Component<Headles
aria-describedby={{if @invalid @errorId}}
...attributes
{{on "input" this.handleInput}}
{{on "focusout" this.handleUnfocus}}
/>
</template>
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

13 changes: 12 additions & 1 deletion test-app/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@
<div class='my-2 flex flex-col'>
<field.Label class={{if field.isInvalid 'text-red-500'}}>Last name</field.Label>
<field.Input
@max="10"
class='border rounded px-2 {{if field.isInvalid "border-red-500"}}'
required
/>
<field.Errors class='text-red-600' />
</div>
</form.Field>

<form.Field @name="rating" as |field|>
<div class="my-2 flex flex-col">
<field.Label class={{if field.isInvalid 'text-red-500'}}>How likely are you to recommend us?</field.Label>
<field.Input
@type="number"
min="1"
max="10"
class="border rounded px-2 {{if field.isInvalid "border-red-500"}}"
/>
</div>
</form.Field>
<form.Field @name='gender' as |field|>
<field.RadioGroup class='my-2 flex flex-col' as |group|>
<group.Label>Gender</group.Label>
Expand Down
21 changes: 9 additions & 12 deletions test-app/config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': '~4.8.0',
// @todo remove this once we have a stable release that includes https://github.com/embroider-build/embroider/pull/1383
'@embroider/core': '2.1.2-unstable.3a9d8ad',
'@embroider/compat': '2.1.2-unstable.3a9d8ad',
'@embroider/webpack': '2.1.2-unstable.3a9d8ad',
'@embroider/core': '3.5.0',
'@embroider/compat': '3.8.0',
'@embroider/webpack': '4.0.9',
},
},
}),
Expand All @@ -66,10 +65,9 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': '~4.8.0',
// @todo remove this once we have a stable release that includes https://github.com/embroider-build/embroider/pull/1383
'@embroider/core': '2.1.2-unstable.3a9d8ad',
'@embroider/compat': '2.1.2-unstable.3a9d8ad',
'@embroider/webpack': '2.1.2-unstable.3a9d8ad',
'@embroider/core': '3.5.0',
'@embroider/compat': '3.8.0',
'@embroider/webpack': '4.0.9',
},
},
}),
Expand All @@ -78,10 +76,9 @@ module.exports = async function () {
npm: {
devDependencies: {
'ember-source': releaseVersion,
// @todo remove this once we have a stable release that includes https://github.com/embroider-build/embroider/pull/1383
'@embroider/core': '2.1.2-unstable.3a9d8ad',
'@embroider/compat': '2.1.2-unstable.3a9d8ad',
'@embroider/webpack': '2.1.2-unstable.3a9d8ad',
'@embroider/core': '3.5.0',
'@embroider/compat': '3.8.0',
'@embroider/webpack': '4.0.9',
},
},
}),
Expand Down

0 comments on commit a12a7b7

Please sign in to comment.