Skip to content

Commit 510f38e

Browse files
committed
copy readme
1 parent 60e492e commit 510f38e

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

projects/dashjoin/json-schema-form/README.md

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
To use the library in your project, follow these steps:
3131

3232
```shell
33-
npm i @angular/material
34-
npm i @angular/flex-layout
35-
npm i @angular/cdk
3633
npm i @dashjoin/json-schema-form
3734
```
3835

@@ -78,35 +75,43 @@ A small sample component:
7875

7976
```typescript
8077
import { Component } from '@angular/core';
81-
import { Schema } from '@dashjoin/json-schema-form/lib/schema';
78+
import { State } from '@dashjoin/json-schema-form';
79+
import { FormArray } from '@angular/forms';
8280
8381
@Component({
8482
selector: 'app-root',
8583
template: `
86-
<lib-json-schema-form [(value)]="value" [schema]="schema" [label]="schema.title"></lib-json-schema-form>
87-
<pre>{{print()}}<pre>
84+
<lib-json-schema-form [state]="state"></lib-json-schema-form>
8885
`
8986
})
9087
export class AppComponent {
9188
92-
schema: Schema = {
93-
type: 'array',
94-
items: {
95-
type: 'object',
96-
properties: {
97-
name: { type: 'string' },
98-
bday: { type: 'string', widget: 'date' }
89+
state: State = {
90+
schema: {
91+
type: 'array',
92+
items: {
93+
type: 'object',
94+
properties: {
95+
name: { type: 'string' },
96+
bday: { type: 'string', widget: 'date' }
97+
}
9998
}
100-
}
99+
},
100+
value: any = [{
101+
name: 'Joe',
102+
bday: '2018-09-09T22:00:00.000Z'
103+
}];
104+
name: 'myform',
105+
106+
// pick FormArray, FormGroup or FormControl for arrays, objects, or single values respectively
107+
control: new FormArray([])
101108
};
102-
103-
value: any = [{
104-
name: 'Joe',
105-
bday: '2018-09-09T22:00:00.000Z'
106-
}];
107-
108-
print(): string {
109-
return JSON.stringify(this.value, null, 2);
109+
110+
foo() {
111+
// subscribe to form value change / validation or state events
112+
this.state.control.valueChanges.subscribe(res => {
113+
console.log(res);
114+
})
110115
}
111116
}
112117
```
@@ -145,7 +150,7 @@ This option specifies a specific input widget to be used. The default is a simpl
145150

146151
It is possible to create custom widgets using the following steps:
147152

148-
* Create a component that implements [WidgetComponent](https://github.com/dashjoin/json-schema-form/blob/master/projects/dashjoin/json-schema-form/src/lib/widget.component.ts). All relevant data such as the applicable subschema and the current value are passed to the component. Make sure to emit value changes. An example can be found [here](https://github.com/dashjoin/json-schema-form/tree/master/src/app/custom.component.ts)
153+
* Create a component that extends [BaseComponent](https://github.com/dashjoin/json-schema-form/blob/master/projects/dashjoin/json-schema-form/src/lib/base/base.component.ts). All relevant data such as the applicable subschema and the current value are passed to the component. Make sure to emit value changes via state.control. An example can be found [here](https://github.com/dashjoin/json-schema-form/blob/master/src/app/custom/custom.component.ts)
149154
* Include the component in your @NgModule declarations
150155
* In the parent component, add this service to your constructor: private service: JsonSchemaFormService
151156
* Register your widget in ngOnInit() using this service: this.service.registerComponent('rich-text-editor', CustomComponent);

0 commit comments

Comments
 (0)