mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Documentation updates for new form injector API
This commit is contained in:
parent
55dc3724db
commit
2b1587894a
@ -510,15 +510,12 @@ Injector.transform(
|
||||
(updater) => {
|
||||
updater.form.alterSchema(
|
||||
'AssetAdmin.*',
|
||||
(updateSchema) => (form, values) => (
|
||||
updateSchema(
|
||||
(values, form) =>
|
||||
form.updateField('Title', {
|
||||
myCustomProp: true
|
||||
})
|
||||
.getState()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
);
|
||||
```
|
||||
@ -552,14 +549,10 @@ Injector.transform(
|
||||
(updater) => {
|
||||
updater.form.addValidation(
|
||||
'AssetAdmin.*',
|
||||
(validate) => (values, errors) => (
|
||||
validate(
|
||||
values,
|
||||
{
|
||||
PostalCode: values.PostalCode.length !== 5 ? 'Invalid postal code' : null
|
||||
}
|
||||
)
|
||||
)
|
||||
(values, errors) => ({
|
||||
...errors,
|
||||
PostalCode: values.PostalCode.length !== 5 ? 'Invalid postal code' : null,
|
||||
})
|
||||
)
|
||||
}
|
||||
);
|
||||
|
@ -49,8 +49,7 @@ Injector.transform(
|
||||
(updater) => {
|
||||
updater.form.alterSchema(
|
||||
'AssetAdmin.*',
|
||||
(updateSchema) => (values, form) => {
|
||||
return updateSchema(
|
||||
(values, form) =>
|
||||
form
|
||||
.updateField('State', {
|
||||
shouldHide: values.Country !== 'US'
|
||||
@ -58,8 +57,6 @@ Injector.transform(
|
||||
.getState()
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
```
|
||||
@ -74,13 +71,10 @@ Injector.transform(
|
||||
(updater) => {
|
||||
updater.form.alterSchema(
|
||||
'AssetAdmin.*',
|
||||
(updateSchema) => (values, form) => {
|
||||
return updateSchema(
|
||||
(values, form) =>
|
||||
form
|
||||
.setFieldClass('Price', 'danger', (values.TicketsRemaining < 10))
|
||||
.getState()
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
@ -122,13 +116,10 @@ Injector.transform(
|
||||
(updater) => {
|
||||
updater.form.alterSchema(
|
||||
'AssetAdmin.*',
|
||||
(updateSchema) => (values, form) => {
|
||||
return updateSchema(
|
||||
(values, form) =>
|
||||
form
|
||||
.setFieldComponent('PhoneNumber', 'PrettyPhoneNumberField')
|
||||
.getState()
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
@ -144,18 +135,15 @@ Injector.transform(
|
||||
(updater) => {
|
||||
updater.form.addValidation(
|
||||
'AssetAdmin.*',
|
||||
(validate) => (values, errors) => {
|
||||
(values, errors) => {
|
||||
const requiredLength = values.Country === 'US' ? 5 : 4;
|
||||
if (!values.Country || !values.PostalCode) {
|
||||
return;
|
||||
}
|
||||
return validate(
|
||||
values,
|
||||
{
|
||||
return {
|
||||
...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() {
|
||||
const extraButtons = [];
|
||||
const { confirmText, cancelText } = this.props;
|
||||
const buttonProps = {
|
||||
...this.props,
|
||||
@ -238,8 +225,7 @@ Injector.transform(
|
||||
(updater) => {
|
||||
updater.form.alterSchema(
|
||||
'AssetAdmin.*',
|
||||
(updateSchema) => (values, form) => {
|
||||
return updateSchema(
|
||||
(values, form) =>
|
||||
form
|
||||
.updateField('action_delete', {
|
||||
confirmText: 'Are you sure you want to delete?',
|
||||
@ -249,6 +235,4 @@ Injector.transform(
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user