Browse Source

Merge pull request #14315 from ArtemDzhereleiko/AD/enh/ai-models

Add pattern to prevent whitespaces for string autocomplete
pull/14357/head
Vladyslav Prykhodko 11 months ago
committed by GitHub
parent
commit
2e63d0daee
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.html
  2. 6
      ui-ngx/src/app/shared/components/string-autocomplete.component.html
  3. 6
      ui-ngx/src/app/shared/components/string-autocomplete.component.scss
  4. 8
      ui-ngx/src/app/shared/components/string-autocomplete.component.ts

1
ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.html

@ -225,6 +225,7 @@
additionalClass="tb-suffix-show-on-hover" additionalClass="tb-suffix-show-on-hover"
appearance="outline" appearance="outline"
panelWidth="" panelWidth=""
showInlineError
required required
[label]="(provider === aiProvider.AZURE_OPENAI ? 'ai-models.deployment-name': 'ai-models.model-id') | translate" [label]="(provider === aiProvider.AZURE_OPENAI ? 'ai-models.deployment-name': 'ai-models.model-id') | translate"
[errorText]="(provider === aiProvider.AZURE_OPENAI ? 'ai-models.deployment-name-required': 'ai-models.model-id-required') | translate" [errorText]="(provider === aiProvider.AZURE_OPENAI ? 'ai-models.deployment-name-required': 'ai-models.model-id-required') | translate"

6
ui-ngx/src/app/shared/components/string-autocomplete.component.html

@ -24,12 +24,12 @@
[matAutocomplete]="optionsAutocomplete"> [matAutocomplete]="optionsAutocomplete">
<button *ngIf="selectionFormControl.value && !disabled" <button *ngIf="selectionFormControl.value && !disabled"
type="button" type="button"
class="tb-icon-24 mr-2" class="tb-icon-24"
matSuffix mat-icon-button aria-label="Clear" matSuffix mat-icon-button aria-label="Clear"
(click)="clear()"> (click)="clear()">
<mat-icon class="material-icons">close</mat-icon> <mat-icon class="material-icons">close</mat-icon>
</button> </button>
<mat-icon *ngIf="selectionFormControl.hasError('required') && selectionFormControl.touched && !showInlineError" <mat-icon *ngIf="selectionFormControl.errors && selectionFormControl.touched && !showInlineError"
matIconSuffix matIconSuffix
[matTooltip]="errorText" [matTooltip]="errorText"
matTooltipPosition="above" matTooltipPosition="above"
@ -37,7 +37,7 @@
class="material-icons tb-suffix-show-always tb-error"> class="material-icons tb-suffix-show-always tb-error">
warning warning
</mat-icon> </mat-icon>
<mat-error *ngIf="selectionFormControl.hasError('required') && showInlineError"> <mat-error *ngIf="selectionFormControl.errors && showInlineError">
{{errorText}} {{errorText}}
</mat-error> </mat-error>
<mat-autocomplete <mat-autocomplete

6
ui-ngx/src/app/shared/components/string-autocomplete.component.scss

@ -20,6 +20,12 @@
max-width: 100%; max-width: 100%;
box-sizing: border-box; box-sizing: border-box;
&.tb-inline-field {
.mdc-icon-button {
margin-right: 8px;
}
}
.tb-autocomplete.tb-option-input-autocomplete { .tb-autocomplete.tb-option-input-autocomplete {
.mat-mdc-option { .mat-mdc-option {
border-bottom: none; border-bottom: none;

8
ui-ngx/src/app/shared/components/string-autocomplete.component.ts

@ -106,7 +106,11 @@ export class StringAutocompleteComponent implements ControlValueAccessor, OnInit
} }
ngOnInit() { ngOnInit() {
this.selectionFormControl = this.fb.control('', this.required ? [Validators.required] : []); const validators = [Validators.pattern(/.*\S.*/)];
if (this.required) {
validators.push(Validators.required);
}
this.selectionFormControl = this.fb.control('', validators);
this.filteredOptions$ = this.selectionFormControl.valueChanges this.filteredOptions$ = this.selectionFormControl.valueChanges
.pipe( .pipe(
tap(value => this.updateView(value)), tap(value => this.updateView(value)),
@ -152,7 +156,7 @@ export class StringAutocompleteComponent implements ControlValueAccessor, OnInit
updateView(value: string) { updateView(value: string) {
this.searchText = value ? value : ''; this.searchText = value ? value : '';
if (this.modelValue !== value) { if (this.modelValue !== value) {
this.modelValue = value; this.modelValue = value?.trim();
this.propagateChange(this.modelValue); this.propagateChange(this.modelValue);
} }
} }

Loading…
Cancel
Save