Loads select items before render

This commit is contained in:
Vlad
2018-01-30 21:19:19 -05:00
parent 87de314c18
commit fef8017134

View File

@@ -12,13 +12,9 @@ define([
const Selection = React.createClass({ const Selection = React.createClass({
getInitialState: function () { getInitialState: function () {
return { return {
items: [],
select2: false, select2: false,
}; };
}, },
componentWillMount: function () {
this.loadCachedItems();
},
allowMultipleValues: function () { allowMultipleValues: function () {
return (this.props.field.multiple === true); return (this.props.field.multiple === true);
}, },
@@ -130,7 +126,7 @@ define([
} }
return null; return null;
}, },
loadCachedItems: function () { loadItems: function () {
let items; let items;
if (typeof (window[`mailpoet_${this.props.field.endpoint}`]) !== 'undefined') { if (typeof (window[`mailpoet_${this.props.field.endpoint}`]) !== 'undefined') {
items = window[`mailpoet_${this.props.field.endpoint}`]; items = window[`mailpoet_${this.props.field.endpoint}`];
@@ -142,11 +138,9 @@ define([
if (this.props.field.filter !== undefined) { if (this.props.field.filter !== undefined) {
items = items.filter(this.props.field.filter); items = items.filter(this.props.field.filter);
} }
this.setState({
items: items,
});
} }
return items;
}, },
handleChange: function (e) { handleChange: function (e) {
let value; let value;
@@ -201,7 +195,8 @@ define([
return undefined; return undefined;
}, },
render: function () { render: function () {
const options = this.state.items.map((item, index) => { const items = this.loadItems(this.props.field);
const options = items.map((item, index) => {
const label = this.getLabel(item); const label = this.getLabel(item);
const searchLabel = this.getSearchLabel(item); const searchLabel = this.getSearchLabel(item);
const value = this.getValue(item); const value = this.getValue(item);