Change 1
Shortened the code to
removeContentNew(i) {
var contents = this.state.templateContent;
contents.splice(i, 1);
this.setState({ templateContent: contents });
}
This may have something to do with this:
componentDidMount() {
this.setState({ templateContent: this.props.template.content });
}
The wrong screen is still deleted. When I register the state, it gives me the correct array. Maybe something is wrong with the map?
-
I am trying to fix this part of the code, but I cannot find the error.
removeContent(i) {
var $formgroup = false;
const regex = new RegExp('^content.', 'i'),
contents = _.reduce(_.keys(this.refs), (memo, k) => {
if (regex.test(k) && k !== 'content.' + i) {
var $formgroup = $(this.refs[k]);
if (this.props.customer.getSetting('wysiwyg_enabled', true)) {
var html = CKEDITOR.instances['html_' + i].getData();
} else {
var html = $formgroup.find('[name="html"]').val();
}
memo.push({
subject: $formgroup.find('[name="subject"]').val(),
html: html,
text: $formgroup.find('[name="text"]').val(),
language: $formgroup.find('[name="language"]').val()
});
}
return memo;
}, []);
this.setState({ templateContent: contents });
}
iis the identifier of the element that I want to remove from the array templateContents. Each time I press the button of removeone of the elements, it always seems that it deletes the latter and ignores the others.
I tested with a variable kand this could be causing problems, but I'm not at all sure.
I am really new to RegExp's way of doing things.
Any ideas how I can fix this?