Skip to content

Commit 84f707f

Browse files
committed
Disable ok button if not reguired fields filled
1 parent 1a9f19f commit 84f707f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

arho_feature_template/gui/plan_attribure_form.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING
55

66
from qgis.PyQt import uic
7-
from qgis.PyQt.QtWidgets import QDialog
7+
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox
88

99
from arho_feature_template.core.models import Plan
1010
from arho_feature_template.project.layers.code_layers import (
@@ -33,6 +33,8 @@ class PlanAttributeForm(QDialog, FormClass): # type: ignore
3333
producers_plan_identifier_line_edit: QLineEdit
3434
matter_management_identifier_line_edit: QLineEdit
3535

36+
button_box: QDialogButtonBox
37+
3638
def __init__(self, parent=None):
3739
super().__init__(parent)
3840

@@ -42,6 +44,25 @@ def __init__(self, parent=None):
4244
self.lifecycle_status_combo_box.populate_from_code_layer(LifeCycleStatusLayer)
4345
self.organisation_combo_box.populate_from_code_layer(OrganisationLayer)
4446

47+
self.name_line_edit.textChanged.connect(self._check_required_fields)
48+
self.organisation_combo_box.currentIndexChanged.connect(self._check_required_fields)
49+
self.plan_type_combo_box.currentIndexChanged.connect(self._check_required_fields)
50+
self.lifecycle_status_combo_box.currentIndexChanged.connect(self._check_required_fields)
51+
52+
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
53+
54+
def _check_required_fields(self) -> None:
55+
ok_button = self.button_box.button(QDialogButtonBox.Ok)
56+
if (
57+
self.name_line_edit.text() != ""
58+
and self.plan_type_combo_box.value() is not None
59+
and self.organisation_combo_box.value() is not None
60+
and self.lifecycle_status_combo_box.value() is not None
61+
):
62+
ok_button.setEnabled(True)
63+
else:
64+
ok_button.setEnabled(False)
65+
4566
def get_plan_attributes(self) -> Plan:
4667
return Plan(
4768
id_=None,

0 commit comments

Comments
 (0)