Skip to content

Commit

Permalink
Disable choice add button in poll wizard when choice limit is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Feb 2, 2025
1 parent 9ca811d commit 3ccf452
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/qt/voting/pollwizarddetailspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ PollWizardDetailsPage::PollWizardDetailsPage(QWidget* parent)
ui->removeChoiceButton->setVisible(!selected.isEmpty());
});
connect(ui->addChoiceButton, &QAbstractButton::clicked, this, [=]() {
if ((size_t) ui->choicesList->model()->rowCount() >= GRC::POLL_MAX_CHOICES_SIZE - 1) {
ui->addChoiceButton->setDisabled(true);
ui->addChoiceButton->setToolTip(tr("Cannot have more than 20 choices in a poll."));
}

ui->choicesList->edit(m_choices_model->addItem());
ui->choicesList->scrollToBottom();
});
Expand All @@ -236,6 +241,11 @@ PollWizardDetailsPage::PollWizardDetailsPage(QWidget* parent)
});
connect(ui->removeChoiceButton, &QAbstractButton::clicked, this, [=]() {
m_choices_model->removeItem(ui->choicesList->selectionModel()->selectedIndexes().first());

if ((size_t) ui->choicesList->model()->rowCount() < GRC::POLL_MAX_CHOICES_SIZE) {
ui->addChoiceButton->setEnabled(true);
ui->addChoiceButton->setToolTip("");
}
});
connect(m_choices_model.get(), &ChoicesListModel::completeChanged, this, [=]() {
emit completeChanged();
Expand Down

0 comments on commit 3ccf452

Please sign in to comment.