2424*/
2525import { NgRedux , select } from '@angular-redux/store' ;
2626import { Component } from '@angular/core' ;
27- import { Actions , JsonFormsState , setLocale } from '@jsonforms/core' ;
27+ import {
28+ Actions ,
29+ getUiSchema ,
30+ JsonFormsState ,
31+ setLocale ,
32+ setReadonly ,
33+ unsetReadonly
34+ } from '@jsonforms/core' ;
2835import { ExampleDescription } from '@jsonforms/examples' ;
2936import { Observable } from 'rxjs' ;
3037@Component ( {
@@ -48,13 +55,17 @@ import { Observable } from 'rxjs';
4855 <button (click)="changeLocale('de-DE')">Change locale to de-DE</button>
4956 <button (click)="changeLocale('en-US')">Change locale to en-US</button>
5057 Current locale: {{ currentLocale }}
58+ <button (click)="setReadonly()">
59+ {{ readonly ? 'Unset' : 'Set' }} Readonly
60+ </button>
5161 </div>
5262 <jsonforms-outlet></jsonforms-outlet>
5363 `
5464} )
5565export class AppComponent {
5666 @select ( [ 'examples' , 'data' ] ) readonly exampleData$ : Observable < any > ;
5767 currentLocale = 'en-US' ;
68+ private readonly = false ;
5869
5970 constructor (
6071 private ngRedux : NgRedux <
@@ -80,4 +91,15 @@ export class AppComponent {
8091 this . currentLocale = locale ;
8192 this . ngRedux . dispatch ( setLocale ( locale ) ) ;
8293 }
94+
95+ setReadonly ( ) {
96+ const uischema = getUiSchema ( this . ngRedux . getState ( ) ) ;
97+ if ( this . readonly ) {
98+ unsetReadonly ( uischema ) ;
99+ } else {
100+ setReadonly ( uischema ) ;
101+ }
102+ this . readonly = ! this . readonly ;
103+ this . ngRedux . dispatch ( Actions . setUISchema ( uischema ) ) ;
104+ }
83105}
0 commit comments