Documentation updates for new form injector API

This commit is contained in:
Aaron Carlino 2017-07-04 09:57:52 +12:00 committed by Daniel Hensby
parent 55dc3724db
commit 2b1587894a
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 30 additions and 53 deletions

View File

@ -510,15 +510,12 @@ Injector.transform(
(updater) => { (updater) => {
updater.form.alterSchema( updater.form.alterSchema(
'AssetAdmin.*', 'AssetAdmin.*',
(updateSchema) => (form, values) => ( (values, form) =>
updateSchema(
form.updateField('Title', { form.updateField('Title', {
myCustomProp: true myCustomProp: true
}) })
.getState() .getState()
) )
)
)
} }
); );
``` ```
@ -552,14 +549,10 @@ Injector.transform(
(updater) => { (updater) => {
updater.form.addValidation( updater.form.addValidation(
'AssetAdmin.*', 'AssetAdmin.*',
(validate) => (values, errors) => ( (values, errors) => ({
validate( ...errors,
values, PostalCode: values.PostalCode.length !== 5 ? 'Invalid postal code' : null,
{ })
PostalCode: values.PostalCode.length !== 5 ? 'Invalid postal code' : null
}
)
)
) )
} }
); );

View File

@ -49,8 +49,7 @@ Injector.transform(
(updater) => { (updater) => {
updater.form.alterSchema( updater.form.alterSchema(
'AssetAdmin.*', 'AssetAdmin.*',
(updateSchema) => (values, form) => { (values, form) =>
return updateSchema(
form form
.updateField('State', { .updateField('State', {
shouldHide: values.Country !== 'US' shouldHide: values.Country !== 'US'
@ -58,8 +57,6 @@ Injector.transform(
.getState() .getState()
) )
} }
)
}
); );
``` ```
@ -74,13 +71,10 @@ Injector.transform(
(updater) => { (updater) => {
updater.form.alterSchema( updater.form.alterSchema(
'AssetAdmin.*', 'AssetAdmin.*',
(updateSchema) => (values, form) => { (values, form) =>
return updateSchema(
form form
.setFieldClass('Price', 'danger', (values.TicketsRemaining < 10)) .setFieldClass('Price', 'danger', (values.TicketsRemaining < 10))
.getState() .getState()
)
}
); );
} }
); );
@ -122,13 +116,10 @@ Injector.transform(
(updater) => { (updater) => {
updater.form.alterSchema( updater.form.alterSchema(
'AssetAdmin.*', 'AssetAdmin.*',
(updateSchema) => (values, form) => { (values, form) =>
return updateSchema(
form form
.setFieldComponent('PhoneNumber', 'PrettyPhoneNumberField') .setFieldComponent('PhoneNumber', 'PrettyPhoneNumberField')
.getState() .getState()
)
}
); );
} }
); );
@ -144,18 +135,15 @@ Injector.transform(
(updater) => { (updater) => {
updater.form.addValidation( updater.form.addValidation(
'AssetAdmin.*', 'AssetAdmin.*',
(validate) => (values, errors) => { (values, errors) => {
const requiredLength = values.Country === 'US' ? 5 : 4; const requiredLength = values.Country === 'US' ? 5 : 4;
if (!values.Country || !values.PostalCode) { if (!values.Country || !values.PostalCode) {
return; return;
} }
return validate( return {
values,
{
...errors, ...errors,
PostalCode: values.PostalCode.length !== requiredLength ? 'Invalid postal code' : null PostalCode: values.PostalCode.length !== requiredLength ? 'Invalid postal code' : null,
} };
);
} }
) )
} }
@ -197,7 +185,6 @@ export default (FormAction) => {
} }
render() { render() {
const extraButtons = [];
const { confirmText, cancelText } = this.props; const { confirmText, cancelText } = this.props;
const buttonProps = { const buttonProps = {
...this.props, ...this.props,
@ -238,8 +225,7 @@ Injector.transform(
(updater) => { (updater) => {
updater.form.alterSchema( updater.form.alterSchema(
'AssetAdmin.*', 'AssetAdmin.*',
(updateSchema) => (values, form) => { (values, form) =>
return updateSchema(
form form
.updateField('action_delete', { .updateField('action_delete', {
confirmText: 'Are you sure you want to delete?', confirmText: 'Are you sure you want to delete?',
@ -249,6 +235,4 @@ Injector.transform(
) )
} }
); );
}
);
``` ```