mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Apply default action props in FormBuilder
Perviously consumers had to props to FormBuilder for styling common actions like 'save'. The props are now automatically passed to FormActions by the FormBuilder. Consumers can override these defaults via the 'createFn' prop.
This commit is contained in:
parent
ae285f3286
commit
5cc6171f77
@ -293,12 +293,21 @@ export class FormBuilderComponent extends SilverStripeComponent {
|
||||
const createFn = this.props.createFn;
|
||||
|
||||
return actions.map((action, i) => {
|
||||
const props = deepFreeze(action);
|
||||
let props = deepFreeze(action);
|
||||
|
||||
if (typeof createFn === 'function') {
|
||||
return createFn(FormActionComponent, props);
|
||||
}
|
||||
|
||||
// Add sensible defaults for common actions.
|
||||
if (props.name === 'action_save') {
|
||||
props = deepFreeze(Object.assign({}, props, {
|
||||
type: 'submit',
|
||||
label: props.title,
|
||||
icon: 'save',
|
||||
}));
|
||||
}
|
||||
|
||||
return <FormActionComponent key={i} {...props} />;
|
||||
});
|
||||
}
|
||||
|
@ -25,8 +25,6 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
},
|
||||
});
|
||||
this.campaignListCreateFn = this.campaignListCreateFn.bind(this);
|
||||
this.campaignEditCreateFn = this.campaignEditCreateFn.bind(this);
|
||||
this.campaignCreationCreateFn = this.campaignCreationCreateFn.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -142,7 +140,6 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
renderDetailEditView() {
|
||||
const baseSchemaUrl = this.props.sectionConfig.forms.DetailEditForm.schemaUrl;
|
||||
const formBuilderProps = {
|
||||
createFn: this.campaignEditCreateFn,
|
||||
formId: 'DetailEditForm',
|
||||
schemaUrl: `${baseSchemaUrl}/ChangeSet/${this.props.campaignId}`,
|
||||
};
|
||||
@ -167,7 +164,6 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
renderCreateView() {
|
||||
const baseSchemaUrl = this.props.sectionConfig.forms.CreateEditForm.schemaUrl;
|
||||
const formBuilderProps = {
|
||||
createFn: this.campaignCreationCreateFn,
|
||||
formId: 'CreateEditForm',
|
||||
schemaUrl: `${baseSchemaUrl}/ChangeSet`,
|
||||
};
|
||||
@ -186,28 +182,6 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to allow customisation of components being constructed
|
||||
* by the Campaign creation FormBuilder.
|
||||
*
|
||||
* @param {Object} Component - Component constructor.
|
||||
* @param {Object} props - Props passed from FormBuilder.
|
||||
* @return {Object} - Instanciated React component
|
||||
*/
|
||||
campaignCreationCreateFn(Component, props) {
|
||||
if (props.name === 'action_save') {
|
||||
const extendedProps = Object.assign({}, props, {
|
||||
type: 'submit',
|
||||
label: props.title,
|
||||
icon: 'save',
|
||||
});
|
||||
|
||||
return <Component key={props.name} {...extendedProps} />;
|
||||
}
|
||||
|
||||
return <Component key={props.name} {...props} />;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to allow customisation of components being constructed
|
||||
* by the Campaign list FormBuilder.
|
||||
@ -266,30 +240,6 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
* Hook to allow customisation of components being constructed
|
||||
* by the Campaign detail edit FormBuilder.
|
||||
*
|
||||
* @param object Component - Component constructor.
|
||||
* @param object props - Props passed from FormBuilder.
|
||||
*
|
||||
* @return object - Instanciated React component
|
||||
*/
|
||||
campaignEditCreateFn(Component, props) {
|
||||
if (props.name === 'action_save') {
|
||||
const extendedProps = Object.assign({}, props, {
|
||||
bootstrapButtonStyle: 'success',
|
||||
type: 'submit',
|
||||
label: props.title,
|
||||
icon: 'save',
|
||||
});
|
||||
|
||||
return <Component key={props.name} {...extendedProps} />;
|
||||
}
|
||||
|
||||
return <Component key={props.name} {...props} />;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets preview URL for itemid
|
||||
* @param int id
|
||||
|
Loading…
Reference in New Issue
Block a user