File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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')"
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')"
Original file line number Diff line number Diff 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
305308const sortTags = ( tags : string [ ] , locale : string ) : string [ ] => {
Original file line number Diff line number Diff 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
232244describe ( 'sortTags' , ( ) => {
You can’t perform that action at this time.
0 commit comments