Skip to content

Insert breaks every time #26

@romanlex

Description

@romanlex

Hello, when I trying get markdown from onChange event by Editor I has double breaks in text.
I want save markdown to another key in my state and save its to database.
What I doing wrong?

<div className={`editor ${this.state.hasFocus ? 'hasFocus' : ''}`}
     onClick={() => { this.editor.focus() }} >
	<Editor
		onFocus={() => this.setState({hasFocus: true})}
		onBlur={e => this.validationDescriptionCheck(e)}
		editorState={this.state.editorState}
		onChange={this.onChange}
		plugins={plugins}
		ref={(element) => { this.editor = element; }}
	/>
	<EmojiSuggestions/>
	<InlineToolbar/>
	{this.state._description === false ?
		<div className="invalid-feedback">{this.state._descriptionMsg}</div> : null}
</div>
	onChange = (editorState) => {
		const markdown = stateToMarkdown(editorState.getCurrentContent());
		this.setState({
			editorState,
			formData: {
				...this.state.formData,
				description: markdown
			}
		});
	};

And my submitHandler:

submitHandler(e) {
	e.preventDefault();
	const { actions } = this.props;
	
	if(this.validate()) {
		let data = this.state.formData;

		let service = new Service(data);

		//TODO удалить
		if(!service.createdAt || service.createdAt === null)
			service.createdAt = moment().format('YYYY-MM-DD HH:mm');
		
		if(this.state.edit === true)
			actions.updateServiceAction(service);
		else
			actions.addServiceAction(service);
	} else {
		actions.error("Данные заполнены не корректно или неполностью");
	}
}

When I call submitHandler I has multiple line-breaks in my string and next save form added another breaks
example first save
image
next save
image

If I save in my formData plaintext(not markdown) all works properly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions