@@ -91,7 +91,7 @@ const myApiDocumentationParser = entrypoint => parseHydraDocumentation(entrypoin
91
91
addField: true,
92
92
addLabel: true
93
93
};
94
-
94
+
95
95
return { api };
96
96
})
97
97
;
@@ -126,7 +126,7 @@ const myApiDocumentationParser = entrypoint => parseHydraDocumentation(entrypoin
126
126
.then( ({ api }) => {
127
127
128
128
const books = api.resources.find(({ name }) => 'books' === name);
129
- const description = books.fields.find(f => 'description' === f. name);
129
+ const description = books.fields.find(({ name }) => 'description' === name);
130
130
131
131
description.input = props => (
132
132
<RichTextInput {...props} source="description" />
@@ -194,11 +194,11 @@ __Note__: In this example, we choose to send the file via a multi-part form data
194
194
195
195
### Using a Custom Validation Function or Inject Custom Props
196
196
197
- You can use ` fieldProps ` and ` inputProps ` to respectively inject custom properties to fields and inputs generated by API
198
- Platform Admin. This is particularly useful to add custom validation rules:
197
+ Example to add a minLength validator on the ` description ` field:
199
198
200
199
``` javascript
201
200
import React , { Component } from ' react' ;
201
+ import { minLength , RichTextInput } from ' react-admin' ;
202
202
import { AdminBuilder , hydraClient } from ' @api-platform-admin' ;
203
203
import parseHydraDocumentation from ' @api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation' ;
204
204
@@ -208,12 +208,13 @@ export default class extends Component {
208
208
state = { api: null };
209
209
210
210
componentDidMount () {
211
- parseHydraDocumentation (entrypoint).then ( ({ api }) => {
212
- const books = api .resources .find (r => ' books' === r . name );
211
+ parseHydraDocumentation (entrypoint).then (({ api }) => {
212
+ const books = api .resources .find (({ name }) => ' books' === name);
213
213
214
- books .writableFields .find (f => ' description' === f .name ).inputProps = {
215
- validate : value => value .length >= 30 ? undefined : ' Minimum length: 30' ;
216
- };
214
+ const description = books .fields .find (({ name }) => ' description' === name)
215
+ description .input = props => (
216
+ < RichTextInput source= {description .name } label= " Description" validate= {minLength (30 )} {... props} / >
217
+ )
217
218
218
219
this .setState ({ api });
219
220
});
0 commit comments