diff --git a/src/FormElement/CheckboxElement.php b/src/FormElement/CheckboxElement.php
index 28782ed6..1e4b5603 100644
--- a/src/FormElement/CheckboxElement.php
+++ b/src/FormElement/CheckboxElement.php
@@ -119,7 +119,11 @@ public function renderUnwrapped()
{
$html = parent::renderUnwrapped();
- return (new HiddenElement($this->getValueOfNameAttribute(), ['value' => $this->getUncheckedValue()])) . $html;
+ $value = $this->getAttribute('disabled')->getValue() && $this->isChecked()
+ ? $this->getCheckedValue()
+ : $this->getUncheckedValue();
+
+ return (new HiddenElement($this->getValueOfNameAttribute(), ['value' => $value])) . $html;
}
/**
diff --git a/tests/FormElement/CheckboxElementTest.php b/tests/FormElement/CheckboxElementTest.php
index c14a5f5e..36aa1303 100644
--- a/tests/FormElement/CheckboxElementTest.php
+++ b/tests/FormElement/CheckboxElementTest.php
@@ -115,6 +115,32 @@ public function testSetCheckValues()
);
}
+ public function testDisabledCheckedCheckboxRendersHiddenElementWithCheckedValue()
+ {
+ $checkbox = new CheckboxElement('test');
+ $checkbox->setChecked(true);
+ $checkbox->getAttributes()->set('disabled', true);
+
+ $this->assertHtml(
+ ''
+ . '',
+ $checkbox
+ );
+ }
+
+ public function testDisabledUncheckedCheckboxRendersHiddenElementWithUncheckedValue()
+ {
+ $checkbox = new CheckboxElement('test');
+ $checkbox->setChecked(false);
+ $checkbox->getAttributes()->set('disabled', true);
+
+ $this->assertHtml(
+ ''
+ . '',
+ $checkbox
+ );
+ }
+
public function testCheckboxNotValidIfRequiredAndUnchecked()
{
$checkbox = new CheckboxElement('test');