Syncing the number of poll options with the drag and drop input

This commit is contained in:
Maxim Khlobystov 2021-03-30 14:33:57 +00:00
parent 70d283eb08
commit 9d4bd0e199

View File

@ -243,8 +243,21 @@ class Poll extends Component {
this.setState({ question: validateInput(e.target.value), error: clearError ? null : error });
}
setOptListLength(len) {
const { optList } = this.state;
const diff = len - optList.length;
if (diff > 0) {
const emptyAddition = Array(diff).fill({ val: '' });
optList.push(...emptyAddition);
} else {
optList.splice(len);
}
this.setState({ optList });
}
pushToCustomPollValues(text) {
const lines = text.split('\n');
this.setOptListLength(lines.length);
for (let i = 0; i < MAX_CUSTOM_FIELDS; i += 1) {
let line = '';
if (i < lines.length) {