diff --git a/src/locales/en.json b/src/locales/en.json index 03eae8fa..4f290012 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -280,6 +280,7 @@ "Flat": "Flat", "Heightmap": "Heightmap", "InvalidNameAlreadyExists": "Profile name already exists, please choose another profile name.", + "InvalidNameAscii": "Name is invalid. Only ascii character are allowed.", "InvalidNameEmpty": "Input must not be empty!", "InvalidNameReserved": "Profile 'default' is reserved, please choose another profile name.", "Later": "Later", diff --git a/src/pages/Heightmap.vue b/src/pages/Heightmap.vue index db32bd8c..0fcc8212 100644 --- a/src/pages/Heightmap.vue +++ b/src/pages/Heightmap.vue @@ -291,8 +291,12 @@ :label="$t('Heightmap.Name')" required :rules="renameInputRules" - @update:error="isInvalidName = !isInvalidName" - @keyup.enter="renameProfile"> + @update:error=" + (bool) => { + isInvalidName = bool + } + " + @keyup.enter="renameProfile" /> @@ -323,13 +327,21 @@ ref="inputFieldCalibrateBedMeshName" v-model="calibrateDialog.name" :label="$t('Heightmap.Name')" + :rules="createInputRules" required - @keyup.enter="calibrateMesh"> + @update:error=" + (bool) => { + calibrateDialog.isInvalidName = bool + } + " + @keyup.enter="calibrateMesh" /> {{ $t('Heightmap.Abort') }} - {{ $t('Heightmap.Calibrate') }} + + {{ $t('Heightmap.Calibrate') }} + @@ -465,17 +477,26 @@ export default class PageHeightmap extends Mixins(BaseMixin, ControlMixin) { private calibrateDialog: { boolShow: boolean name: string + isInvalidName: boolean } = { boolShow: false, name: 'default', + isInvalidName: false, } private newName = '' private oldName = '' private isInvalidName = true + private createInputRules = [ + (value: string) => !!value || this.$t('Heightmap.InvalidNameEmpty'), + // eslint-disable-next-line no-control-regex + (value: string) => value === value.replace(/[^\x00-\x7F]/g, '') || this.$t('Heightmap.InvalidNameAscii'), + ] private renameInputRules = [ (value: string) => !!value || this.$t('Heightmap.InvalidNameEmpty'), (value: string) => value !== 'default' || this.$t('Heightmap.InvalidNameReserved'), (value: string) => !this.existsProfileName(value) || this.$t('Heightmap.InvalidNameAlreadyExists'), + // eslint-disable-next-line no-control-regex + (value: string) => value === value.replace(/[^\x00-\x7F]/g, '') || this.$t('Heightmap.InvalidNameAscii'), ] private probedOpacity = 1 @@ -1038,6 +1059,7 @@ export default class PageHeightmap extends Mixins(BaseMixin, ControlMixin) { this.newName = this.bed_mesh?.profile_name ?? '' this.oldName = this.bed_mesh.profile_name this.renameDialog = true + this.isInvalidName = false setTimeout(() => { this.$refs.inputDialogRenameHeightmapName?.focus()