Merge pull request #6434 from kalutkaz/fix/validationJsonEditor
[3.4] UI: Fix validation logic for JSON
This commit is contained in:
commit
0adcb36d10
@ -26,6 +26,7 @@ import {
|
|||||||
Validator
|
Validator
|
||||||
} from '@angular/forms';
|
} from '@angular/forms';
|
||||||
import { ErrorStateMatcher } from '@angular/material/core';
|
import { ErrorStateMatcher } from '@angular/material/core';
|
||||||
|
import { isObject } from "@core/utils";
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[tb-json-to-string]',
|
selector: '[tb-json-to-string]',
|
||||||
@ -53,7 +54,11 @@ export class TbJsonToStringDirective implements ControlValueAccessor, Validator,
|
|||||||
@HostListener('input', ['$event.target.value']) input(newValue: any): void {
|
@HostListener('input', ['$event.target.value']) input(newValue: any): void {
|
||||||
try {
|
try {
|
||||||
this.data = JSON.parse(newValue);
|
this.data = JSON.parse(newValue);
|
||||||
|
if (isObject(this.data)) {
|
||||||
this.parseError = false;
|
this.parseError = false;
|
||||||
|
} else {
|
||||||
|
this.parseError = true;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.parseError = true;
|
this.parseError = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import { ActionNotificationHide, ActionNotificationShow } from '@core/notificati
|
|||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppState } from '@core/core.state';
|
import { AppState } from '@core/core.state';
|
||||||
import { CancelAnimationFrame, RafService } from '@core/services/raf.service';
|
import { CancelAnimationFrame, RafService } from '@core/services/raf.service';
|
||||||
import { guid, isDefinedAndNotNull, isLiteralObject, isUndefined } from '@core/utils';
|
import { guid, isDefinedAndNotNull, isObject, isUndefined } from '@core/utils';
|
||||||
import { ResizeObserver } from '@juggle/resize-observer';
|
import { ResizeObserver } from '@juggle/resize-observer';
|
||||||
import { getAce } from '@shared/models/ace/ace.models';
|
import { getAce } from '@shared/models/ace/ace.models';
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va
|
|||||||
if (this.contentValue && this.contentValue.length > 0) {
|
if (this.contentValue && this.contentValue.length > 0) {
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(this.contentValue);
|
data = JSON.parse(this.contentValue);
|
||||||
if (!isLiteralObject(data)) {
|
if (!isObject(data)) {
|
||||||
throw new TypeError(`Value is not a valid JSON`);
|
throw new TypeError(`Value is not a valid JSON`);
|
||||||
}
|
}
|
||||||
this.objectValid = true;
|
this.objectValid = true;
|
||||||
|
|||||||
@ -202,7 +202,7 @@ export const valueTypesMap = new Map<ValueType, ValueTypeData>(
|
|||||||
ValueType.JSON,
|
ValueType.JSON,
|
||||||
{
|
{
|
||||||
name: 'value.json',
|
name: 'value.json',
|
||||||
icon: 'mdi:json'
|
icon: 'mdi:code-json'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user