fix: admin/fs: source field was allowing newline characters
Massimo Melina committed
Oct 21, 2023 at 04:03 UTC
543e50a1fbf0c515ad8aa18a7dc942bdb7d14144
3 files changed
+10
-4
admin/src/FileField.ts
+2
@@ -15,7 +15,9 @@ export default function FileField({ value, onChange, files=true, folders=false,
15
...props,
16
value,
17
onChange,
18
+ onTyping: (v: string) => !v.includes('\n') && v,
19
InputProps: {
20
+ multiline: true,
21
endAdornment: h(InputAdornment, { position: 'end' },
22
h(IconBtn, {
23
icon: Eject,
admin/src/FileForm.ts
+1
-1
@@ -103,7 +103,7 @@ export default function FileForm({ file, anyMask, addToBar, statusApi }: FileFor
103
fields: [
104
isRoot ? h(Alert,{ severity: 'info' }, "This is Home, the root of your shared files. Options set here will be applied to all files.")
105
: { k: 'name', required: true, xl: 6, helperText: hasSource && "You can decide a name that's different from the one on your disk" },
106
- { k: 'source', label: "Source on disk", xl: true, comp: FileField, files: !isDir, folders: isDir, multiline: true,
106
+ { k: 'source', label: "Source on disk", xl: true, comp: FileField, files: !isDir, folders: isDir,
107
helperText: !values.source && "Not on disk, this is a virtual folder",
108
},
109
{ k: 'id', comp: LinkField, statusApi, xs: 12 },
mui-grid-form/StringField.ts
+7
-3
@@ -7,7 +7,7 @@ import { StandardTextFieldProps } from '@mui/material/TextField/TextField'
7
8
interface StringFieldProps extends FieldProps<string>, Partial<Omit<StandardTextFieldProps, 'label' | 'onChange' | 'value'>> {
9
typing?: boolean // change state as the user is typing
10
- onTyping?: (v: string) => boolean
10
+ onTyping?: (v: string) => string | false
11
min?: number
12
max?: number
13
required?: boolean
@@ -39,8 +39,12 @@ export function StringField({ value, onChange, min, max, required, setApi, typin
39
sx: props.label ? props.sx : Object.assign({ '& .MuiInputBase-input': { pt: 1.5 } }, props.sx),
40
value: state,
41
onChange(ev) {
42
- const val = ev.target.value
43
- if (onTyping?.(val) === false) return
42
+ let val = ev.target.value
43
+ if (onTyping) {
44
+ const res = onTyping(val)
45
+ if (res === false) return
46
+ val = res
47
+ }
48
setState(val)
49
if (typing || valueFocusing.current === undefined)
50
go(ev, val)