Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): adding space as non-valid character #457

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions src/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
13 changes: 11 additions & 2 deletions src/views/standalone/system/ControllerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -153,7 +158,11 @@ function validate() {
errorBag.value.clear()

const validators: [validationOutput[], string, Ref<any>][] = [
[[validateRequired(unitName.value)], 'unit_name', unitNameRef],
[
[validateRequired(unitName.value), validateNoSpaces(unitName.value)],
'unit_name',
unitNameRef
],
[[validateRequired(controllerJoinCode.value)], 'join_code', controllerJoinCodeRef]
]

Expand Down