From 3ccf4527f8b18f4bc21d212a1f481516967d2591 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sat, 1 Feb 2025 17:54:40 -0500 Subject: [PATCH] Disable choice add button in poll wizard when choice limit is reached --- src/qt/voting/pollwizarddetailspage.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/qt/voting/pollwizarddetailspage.cpp b/src/qt/voting/pollwizarddetailspage.cpp index 1e75926e76..2ed590141b 100644 --- a/src/qt/voting/pollwizarddetailspage.cpp +++ b/src/qt/voting/pollwizarddetailspage.cpp @@ -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(); }); @@ -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();