diff --git a/src/i18n/en/translation.json b/src/i18n/en/translation.json index 39b449331..0775b09c4 100644 --- a/src/i18n/en/translation.json +++ b/src/i18n/en/translation.json @@ -386,7 +386,8 @@ "cannot_retrieve_talkers_list": "Cannot retrieve talkers list", "invalid_number": "Invalid number", "network_conflict": "This name is already in use by another network interface", - "cannot_retrieve_latency_and_quality_report": "Cannot retrieve latency and quality report" + "cannot_retrieve_latency_and_quality_report": "Cannot retrieve latency and quality report", + "invalid_space": "Field cannot contain spaces" }, "ne_text_input": { "show_password": "Show password", diff --git a/src/lib/validation.ts b/src/lib/validation.ts index 9376bb2ce..c00842a28 100644 --- a/src/lib/validation.ts +++ b/src/lib/validation.ts @@ -722,6 +722,17 @@ export const validateDNSForwardingServer = (value: string): validationOutput => return validResult } +/** + * Validate if the string doesn't have spaces. + * @param value + */ +export function validateNoSpaces(value: string): validationOutput { + if (value.includes(' ')) { + return { valid: false, errMessage: 'error.invalid_space' } + } + return { valid: true } +} + /** * Validate a 6-digit code * diff --git a/src/views/standalone/system/ControllerView.vue b/src/views/standalone/system/ControllerView.vue index 280c7059b..c442f327e 100644 --- a/src/views/standalone/system/ControllerView.vue +++ b/src/views/standalone/system/ControllerView.vue @@ -23,7 +23,12 @@ import { useI18n } from 'vue-i18n' import FormLayout from '@/components/standalone/FormLayout.vue' import { onMounted, onUnmounted, ref, type Ref } from 'vue' import { ubusCall, ValidationError } from '@/lib/standalone/ubus' -import { MessageBag, validateRequired, type validationOutput } from '@/lib/validation' +import { + MessageBag, + validateRequired, + validateNoSpaces, + type validationOutput +} from '@/lib/validation' import { useRoute } from 'vue-router' import { getStandaloneRoutePrefix } from '@/lib/router' @@ -153,7 +158,11 @@ function validate() { errorBag.value.clear() const validators: [validationOutput[], string, Ref][] = [ - [[validateRequired(unitName.value)], 'unit_name', unitNameRef], + [ + [validateRequired(unitName.value), validateNoSpaces(unitName.value)], + 'unit_name', + unitNameRef + ], [[validateRequired(controllerJoinCode.value)], 'join_code', controllerJoinCodeRef] ]