Skip to content

Commit 65077d3

Browse files
committed
🔨 Migrate number input to text input
1 parent 51ca018 commit 65077d3

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

frontend/src/modals/SongSet.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787
<label class="flex flex-col gap-1">
8888
<div>{{ t('field.year') }}</div>
8989
<input
90-
type="number"
90+
type="text"
91+
inputmode="numeric"
9192
:value="song.year"
9293
@input="e => song.year = parseNumberInput((e.target as HTMLInputElement).value)"
9394
:placeholder="t('placeholder.exampleSongYear')"
@@ -111,7 +112,8 @@
111112
<icon-number class="w-5 h-5 stroke-1.5 mt-0.5" />
112113
</div>
113114
<input
114-
type="number"
115+
type="text"
116+
inputmode="numeric"
115117
:value="song.ccli"
116118
@input="e => song.ccli = parseNumberInput((e.target as HTMLInputElement).value)"
117119
:placeholder="t('placeholder.exampleSongCcli')"

frontend/src/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@ const urlify = (s: string): string => {
299299
}
300300

301301
// parse a number <input>'s raw value, treating an empty field as unset rather than 0
302-
const parseNumberInput = (value: string): number | undefined => value === '' ? undefined : parseInt(value);
302+
const parseNumberInput = (value: string): number | undefined => {
303+
const trimmed = value.trim();
304+
return trimmed === '' ? undefined : parseInt(trimmed);
305+
};
303306

304307
// sort tag keys by their translated name in the given locale
305308
const sortTags = (tags: string[], locale: string): string[] => {

frontend/tests/utils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ describe('parseNumberInput', () => {
227227
it('parses a numeric string', () => {
228228
expect(parseNumberInput('42')).toBe(42);
229229
});
230+
231+
it('trims a trailing space before parsing', () => {
232+
expect(parseNumberInput('12345 ')).toBe(12345);
233+
});
234+
235+
it('trims a leading space before parsing', () => {
236+
expect(parseNumberInput(' 12345')).toBe(12345);
237+
});
238+
239+
it('treats a whitespace-only string as unset', () => {
240+
expect(parseNumberInput(' ')).toBeUndefined();
241+
});
230242
});
231243

232244
describe('sortTags', () => {

0 commit comments

Comments
 (0)