Skip to content

Commit 3afb0d3

Browse files
committed
fix: enhance resource group name validation logic for spaces and special characters (#2916)
### This PR resolves [#2915](#2915) issue Related PR: [control-panel#930](lablup/backend.ai-control-panel#930) **Changes:** Currently, validation rules are not applied in Backend.AI Core, but plan to add them to the scope of domain and project in the future. Therefore, �I added validation rules (allow dot and unicode) to match the rules on the core side. **Invalid strings:** - contains special characters - consisting of leading, trailing, or only spaces, or more than one space between characters. - empty string **How to test:** - Move to resources page and click resource group tab - Create a new resource group and verify that the validation rule works correctly.
1 parent 9c37a81 commit 3afb0d3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/backend-ai-resource-group-list.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,14 @@ export default class BackendAIResourceGroupList extends BackendAIPage {
365365
valid: nativeValidity.valid,
366366
valueMissing: !nativeValidity.valid,
367367
};
368+
} else if (nativeValidity.patternMismatch) {
369+
this.resourceGroupNameInput.validationMessage = _text(
370+
'resourceGroup.EnterValidResourceGroupName',
371+
);
372+
return {
373+
valid: nativeValidity.valid,
374+
patternMismatch: !nativeValidity.valid,
375+
};
368376
} else {
369377
this.resourceGroupNameInput.validationMessage = _text(
370378
'resourceGroup.EnterValidResourceGroupName',
@@ -459,7 +467,8 @@ export default class BackendAIResourceGroupList extends BackendAIPage {
459467
this.notification.show(true, err);
460468
});
461469
} else {
462-
// ResourceGroupNameEl.reportValidity();
470+
this._validateResourceGroupName();
471+
this.resourceGroupNameInput.reportValidity();
463472
return;
464473
}
465474
}
@@ -845,10 +854,10 @@ export default class BackendAIResourceGroupList extends BackendAIPage {
845854
label="${_t('resourceGroup.ResourceGroupName')}"
846855
maxLength="64"
847856
placeholder="${_t('maxLength.64chars')}"
848-
validationMessage="${_t('data.explorer.ValueRequired')}"
849857
required
850858
autoValidate
851-
@change="${() => this._validateResourceGroupName()}"
859+
pattern="^[\\p{L}\\p{N}]+(?:[\\-_.][\\p{L}\\p{N}]+)*$"
860+
@input="${() => this._validateResourceGroupName()}"
852861
></mwc-textfield>
853862
`
854863
: html`

0 commit comments

Comments
 (0)