-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to reset to default/initial values after editing some values? #26
Comments
You can do it by cloning the initial value before passing it to the component |
cloning we can do, but how to set the cloned value to json editor, should I replace the IntialValue with cloned value? |
is there any way to change the value through javascript and reflect the same in html? |
Yes, replace the initial value, if the UI doesn't change, you can trigger a force change by |
I tried ChangeDetectionStrategy in reset() but it doesn't worked on json-editor. below is code snippet. import { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core' reset() { is there any set() method for json-editor where I can provide values to set something on some of the html element rendered by json-editor? |
ChangeDetectionStrategry works for other html element but it doesn't work for initialValue. seems that json-editor considers initialValue only when json editor's gets initialize i.e. during onInit() and it doesn't consider if we change the value of initialValue after rendering of json-editor. |
No |
Yes, ng-if works but it's seems to hack so I don't want to go with it. consider below schema where the user can select car make and accordingly predefined color and engine property should set. preset = { schema = { |
Pull request is welcome if you want to improve this about |
Version(if relevant): 1.0.0
Environment(if relevant):
I'm using angular version 8.0.0
In HTML page, I have 'save' and 'reset' buttons.
what I want here is, once the page is loaded, JSON editor should load with initial values and if the user edit some values and click on the 'reset' button. all values should get clear and reset it with some default/initial values.
is there any way to reset the values?
below is html and ts code
<json-editor [schema]="schema"
[initialValue]="initialValue"
(updateValue)="updateValue($event)"
theme="bootstrap3">
<button id="reset" class="btn btn-submit" (click)="reset()">Reset
Save
and in app.component.ts
schema = {
type : 'object',
title: 'json editor',
properties: {
color: {
type: 'string',
default: 'red'
},
engine: {
type: 'string',
default: '1111'
}, required: ['color','engine']
}
initialValue= {
color: 'green',
engine: '88'
};
updateValue({ value, isValid }: common.ValidityValue<common.ValueType>) {
this.currentValues = values;
}
reset() {
//??
}
The text was updated successfully, but these errors were encountered: