Skip to content

Commit

Permalink
Merge pull request #347 from josemarluedke/chore/form-data
Browse files Browse the repository at this point in the history
feat: use form-data-utils to get form data
  • Loading branch information
josemarluedke authored Feb 13, 2025
2 parents d9d7e29 + 8a63d2e commit 6cf0631
Show file tree
Hide file tree
Showing 6 changed files with 11,545 additions and 15,143 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A modern, accessible, and extensible component library for Ember.js, built with

## 🚀 Features

- _Fully Customizable_ – Uses Tailwind Variants for styling.
- _Fully Customizable_ – Uses Tailwind CSS with Tailwind Variants for styling.
- _Accessible Components_ – Follows best practices for a11y.
- _Composable & Extensible_ – Designed to be customized and extended to fit any design system.
- _Built for Ember_ – Seamless integration with Ember Octane & Glimmer components.
Expand Down
3 changes: 2 additions & 1 deletion packages/forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"@frontile/theme": "workspace:0.17.0-beta.10",
"@frontile/utilities": "workspace:0.17.0-beta.10",
"@glint/template": "1.5.2",
"ember-modifier": "^4.1.0"
"ember-modifier": "^4.1.0",
"form-data-utils": "^0.6.0"
},
"devDependencies": {
"@babel/core": "7.26.7",
Expand Down
23 changes: 3 additions & 20 deletions packages/forms/src/components/form.gts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Component from '@glimmer/component';
import { on } from '@ember/modifier';
import { dataFrom } from 'form-data-utils';

type FormDataEntryValue = NonNullable<ReturnType<FormData['get']>>;
type FormResultData = Record<string, FormDataEntryValue>;
type FormResultData = ReturnType<typeof dataFrom>;

interface FormSignature {
Element: HTMLFormElement;
Expand All @@ -25,24 +25,7 @@ class Form extends Component<FormSignature> {
) => {
const form = event.currentTarget;
if (form instanceof HTMLFormElement) {
let formData = new FormData(form);

for (let i = 0; i < form.elements.length; i++) {
const element = form.elements[i] as HTMLSelectElement;
if (element.type === 'select-multiple') {
const selectedValues = [];
for (let j = 0; j < element.options.length; j++) {
const option = element.options[j];
if (option && option.selected) {
selectedValues.push(option.value);
}
}
formData.append(element.name, selectedValues.join(','));
}
}

let data = Object.fromEntries(formData.entries());

const data = dataFrom(event);
this.args.onChange(data, eventType, event);
}
};
Expand Down
Loading

0 comments on commit 6cf0631

Please sign in to comment.