Skip to content

Commit 74bc2a3

Browse files
committed
fix: do not render placeholder on unsubmitted and non-persistent forms
1 parent 07f2fea commit 74bc2a3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/FormElement/PasswordElement.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ class PasswordElement extends InputElement
1515
/** @var bool Status of the form */
1616
protected $isFormValid = true;
1717

18+
/** @var bool Status indicating if the form got submitted */
19+
protected $isFormSubmitted = false;
20+
1821
protected function registerAttributeCallbacks(Attributes $attributes)
1922
{
2023
parent::registerAttributeCallbacks($attributes);
2124

2225
$attributes->registerAttributeCallback(
2326
'value',
2427
function () {
25-
if ($this->hasValue() && count($this->getValueCandidates()) === 1 && $this->isFormValid) {
28+
if (
29+
$this->hasValue()
30+
&& count($this->getValueCandidates()) === 1
31+
&& $this->isFormValid
32+
&& ! $this->isFormSubmitted
33+
) {
2634
return self::DUMMYPASSWORD;
2735
}
2836

29-
if (parent::getValue() === self::DUMMYPASSWORD) {
37+
if (parent::getValue() === self::DUMMYPASSWORD && count($this->getValueCandidates()) > 1) {
3038
return self::DUMMYPASSWORD;
3139
}
3240

@@ -40,6 +48,10 @@ public function onRegistered(Form $form)
4048
$form->on(Form::ON_VALIDATE, function ($form) {
4149
$this->isFormValid = $form->isValid();
4250
});
51+
52+
$form->on(Form::ON_SENT, function ($form) {
53+
$this->isFormSubmitted = $form->hasBeenSent();
54+
});
4355
}
4456

4557
public function getValue()

0 commit comments

Comments
 (0)