1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

[SM-628] Add trim validator to SM dialogs (#4993)

* Add trim validator to SM dialogs

* Swap to creating a generic component

* Swap to BitValidators.trimValidator

* Fix storybook

* update validator to auto trim whitespace

* update storybook copy

* fix copy

* update trim validator to run on submit

* add validator to project name in secret dialog; update secret name validation to on submit

---------

Co-authored-by: William Martin <contact@willmartian.com>
This commit is contained in:
Thomas Avery
2023-05-30 17:52:02 -05:00
committed by GitHub
parent 4a552343f1
commit 2f44b9b0dd
10 changed files with 149 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ import { Router } from "@angular/router";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { BitValidators } from "@bitwarden/components";
import { ProjectView } from "../../models/view/project.view";
import { ProjectService } from "../../projects/project.service";
@@ -25,7 +26,10 @@ export interface ProjectOperation {
})
export class ProjectDialogComponent implements OnInit {
protected formGroup = new FormGroup({
name: new FormControl("", [Validators.required]),
name: new FormControl("", {
validators: [Validators.required, BitValidators.trimValidator],
updateOn: "submit",
}),
});
protected loading = false;

View File

@@ -8,6 +8,7 @@ import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Utils } from "@bitwarden/common/misc/utils";
import { BitValidators } from "@bitwarden/components";
import { ProjectListView } from "../../models/view/project-list.view";
import { ProjectView } from "../../models/view/project.view";
@@ -36,11 +37,20 @@ export interface SecretOperation {
})
export class SecretDialogComponent implements OnInit {
protected formGroup = new FormGroup({
name: new FormControl("", [Validators.required]),
name: new FormControl("", {
validators: [Validators.required, BitValidators.trimValidator],
updateOn: "submit",
}),
value: new FormControl("", [Validators.required]),
notes: new FormControl(""),
notes: new FormControl("", {
validators: [BitValidators.trimValidator],
updateOn: "submit",
}),
project: new FormControl("", [Validators.required]),
newProjectName: new FormControl(""),
newProjectName: new FormControl("", {
validators: [BitValidators.trimValidator],
updateOn: "submit",
}),
});
private destroy$ = new Subject<void>();

View File

@@ -3,6 +3,8 @@ import { Component, Inject, OnInit } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms";
import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { BitValidators } from "@bitwarden/components";
import { ServiceAccountView } from "../../../models/view/service-account.view";
import { AccessTokenView } from "../../models/view/access-token.view";
@@ -20,7 +22,10 @@ export interface AccessTokenOperation {
})
export class AccessTokenCreateDialogComponent implements OnInit {
protected formGroup = new FormGroup({
name: new FormControl("", [Validators.required, Validators.maxLength(80)]),
name: new FormControl("", {
validators: [Validators.required, Validators.maxLength(80), BitValidators.trimValidator],
updateOn: "submit",
}),
expirationDateControl: new FormControl(null),
});
protected loading = false;
@@ -30,6 +35,7 @@ export class AccessTokenCreateDialogComponent implements OnInit {
constructor(
public dialogRef: DialogRef,
@Inject(DIALOG_DATA) public data: AccessTokenOperation,
private i18nService: I18nService,
private dialogService: DialogServiceAbstraction,
private accessService: AccessService
) {}

View File

@@ -4,6 +4,7 @@ import { FormControl, FormGroup, Validators } from "@angular/forms";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { BitValidators } from "@bitwarden/components";
import { ServiceAccountView } from "../../models/view/service-account.view";
import { ServiceAccountService } from "../service-account.service";
@@ -23,9 +24,15 @@ export interface ServiceAccountOperation {
templateUrl: "./service-account-dialog.component.html",
})
export class ServiceAccountDialogComponent {
protected formGroup = new FormGroup({
name: new FormControl("", [Validators.required]),
});
protected formGroup = new FormGroup(
{
name: new FormControl("", {
validators: [Validators.required, BitValidators.trimValidator],
updateOn: "submit",
}),
},
{}
);
protected loading = false;