Skip to content

Commit

Permalink
feat(validation): add length validation for mwan name rule (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl authored Oct 17, 2024
1 parent 79b3e44 commit 56bfaea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/standalone/multi-wan/RuleCreator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function save() {
<NeTextInput
v-model.trim="name"
:disabled="saving"
:invalid-message="t(validationErrors.getFirstI18nKeyFor('name'))"
:invalid-message="validationErrors.getFirstFor('name')"
:label="t('standalone.multi_wan.rule_name')"
:placeholder="t('standalone.multi_wan.rule_name')"
name="rule_name"
Expand Down
7 changes: 6 additions & 1 deletion src/composables/useRuleForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
MessageBag,
validateIp4OrCidr,
validatePortRangeForMwan,
validateRequired
validateRequired,
validateUciName
} from '@/lib/validation'
import { type ObjectReference, useObjects } from '@/composables/useObjects'
import { ubusCall } from '@/lib/standalone/ubus'
Expand Down Expand Up @@ -171,6 +172,10 @@ export function useRuleForm(policies: Ref<Policy[]>, rule?: Ref<Rule | undefined
if (!validationCheck.valid) {
validationErrors.value.set('policy', String(validationCheck.errMessage))
}
const { valid, errMessage, i18Params } = validateUciName(name.value, 12)
if (!valid) {
validationErrors.value.set('name', t(errMessage as string, i18Params as any))
}
if (sourceAddress.value != '') {
validationCheck = validateIp4OrCidr(sourceAddress.value)
if (!validationCheck.valid) {
Expand Down

0 comments on commit 56bfaea

Please sign in to comment.