Add new layout dynamic

This commit is contained in:
cyril lopez 2018-03-19 12:30:04 +01:00
parent 67cb54ae12
commit 0952c9aaa9
3 changed files with 12 additions and 8 deletions

View File

@ -51,6 +51,11 @@ class Wysiwyg extends React.Component {
this.setState({ isFocused: true }); this.setState({ isFocused: true });
return this.domEditor.focus(); return this.domEditor.focus();
}; };
this.blur = () => {
this.setState({ isFocused: false });
return this.domEditor.blur();
};
} }
componentDidMount() { componentDidMount() {
@ -348,7 +353,7 @@ class Wysiwyg extends React.Component {
onChange = (editorState) => { onChange = (editorState) => {
// Update the state and force the focus // Update the state and force the focus
this.setState({ editorState }, () => { this.focus(); }); this.setState({ editorState });
this.props.onChange({ target: { this.props.onChange({ target: {
value: editorState.getCurrentContent().getPlainText(), value: editorState.getCurrentContent().getPlainText(),
name: this.props.name, name: this.props.name,
@ -450,7 +455,7 @@ class Wysiwyg extends React.Component {
editorState={editorState} editorState={editorState}
handleKeyCommand={this.handleKeyCommand} handleKeyCommand={this.handleKeyCommand}
keyBindingFn={this.mapKeyToEditorCommand} keyBindingFn={this.mapKeyToEditorCommand}
onBlur={() => this.setState({ isFocused: false })} onBlur={this.blur}
onChange={this.onChange} onChange={this.onChange}
placeholder={this.props.placeholder} placeholder={this.props.placeholder}
setRef={(editor) => this.domEditor = editor} setRef={(editor) => this.domEditor = editor}

View File

@ -137,6 +137,8 @@ class Edit extends React.PureComponent {
const details = this.state.displayedFields[attr]; const details = this.state.displayedFields[attr];
// Retrieve the input's bootstrapClass from the layout // Retrieve the input's bootstrapClass from the layout
const layout = this.getInputLayout(attr); const layout = this.getInputLayout(attr);
const appearance = get(layout, 'appearance');
const type = !isEmpty(appearance) ? appearance.toLowerCase() : get(layout, 'type', getInputType(details.type));
return ( return (
<Input <Input
@ -151,7 +153,7 @@ class Edit extends React.PureComponent {
onChange={this.props.onChange} onChange={this.props.onChange}
selectOptions={get(this.props.attributes, [attr, 'enum'])} selectOptions={get(this.props.attributes, [attr, 'enum'])}
placeholder={get(layout, 'placeholder') || details.placeholder} placeholder={get(layout, 'placeholder') || details.placeholder}
type={get(layout, 'type', getInputType(details.type))} type={type}
validations={this.getInputValidations(attr)} validations={this.getInputValidations(attr)}
value={this.props.record[attr]} value={this.props.record[attr]}
/> />

View File

@ -32,9 +32,6 @@ import getQueryParameters from 'utils/getQueryParameters';
import { bindLayout } from 'utils/bindLayout'; import { bindLayout } from 'utils/bindLayout';
import { checkFormValidity } from 'utils/formValidations'; import { checkFormValidity } from 'utils/formValidations';
// Layout
import layout from '../../../../config/layout';
import { import {
changeData, changeData,
getData, getData,
@ -109,7 +106,7 @@ export class EditPage extends React.Component {
* @return {[type]} [description] * @return {[type]} [description]
*/ */
getLayout = () => ( getLayout = () => (
bindLayout.call(this, get(this.context.plugins.toJS(), `${this.getSource()}.layout`, layout)) bindLayout.call(this, this.props.editPage.layout)
) )
/** /**
@ -174,7 +171,7 @@ export class EditPage extends React.Component {
this.props.setFormErrors(formErrors); this.props.setFormErrors(formErrors);
} }
layout = bindLayout.call(this, layout); // layout = bindLayout.call(this, layout);
componentDidCatch(error, info) { componentDidCatch(error, info) {
console.log('err', error); console.log('err', error);