Skip to content

Commit

Permalink
add JSON validator to filter string textarea input
Browse files Browse the repository at this point in the history
  • Loading branch information
infacc committed Jul 20, 2023
1 parent 37526f4 commit 6a33202
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h3 class="editor-description">Filter Editor</h3>
<button mat-raised-button class="copy-button" type="button" (click)="copyFilterString()">
<mat-icon>content_copy</mat-icon>
</button>
<mat-error *ngIf="filterControl.hasError('invalidJSON')">Invalid JSON</mat-error>
</mat-form-field>
<details>
<summary>Filter String Info</summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { AbstractControl, FormControl, Validators, ValidatorFn } from '@angular/forms';
import { ApiLink } from 'src/app/services/api-data-types';
import { PluginRegistryBaseService } from 'src/app/services/registry.service';
import { TemplateTabApiObject } from 'src/app/services/templates.service';

export function isJSONValidator(): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => {
try {
JSON.parse(control.value);
return null;
} catch (e) {
return { invalidJSON: true };
}
};
}

@Component({
selector: 'qhana-plugin-filter-editor',
templateUrl: './plugin-filter-editor.component.html',
Expand All @@ -14,7 +25,8 @@ export class PluginFilterEditorComponent implements OnInit {
@Output() filterEmitter: EventEmitter<string> = new EventEmitter<string>();

filterString: string = "{}";
filterControl = new FormControl(this.filterString, [Validators.required, Validators.minLength(2)]); // TODO: Add validator for JSON
// TODO: Add JSON validator for filter strings
filterControl = new FormControl(this.filterString, [isJSONValidator()]);

filterObject: any = {};

Expand Down

0 comments on commit 6a33202

Please sign in to comment.