diff --git a/src/Forms/Controls/TextInput.php b/src/Forms/Controls/TextInput.php index a5c6d8a5c..9f7a8d004 100644 --- a/src/Forms/Controls/TextInput.php +++ b/src/Forms/Controls/TextInput.php @@ -63,6 +63,10 @@ public function getControl() foreach ($this->getRules() as $rule) { if ($rule->isNegative || $rule->branch) { + } elseif ($input->type === 'text' && in_array($rule->validator, [Form::EMAIL, Form::URL, Form::INTEGER, Form::FLOAT], TRUE)) { + static $types = [Form::EMAIL => 'email', Form::URL => 'url', Form::INTEGER => 'number', Form::FLOAT => 'number']; + $input->type = $types[$rule->validator]; + } elseif (in_array($rule->validator, [Form::MIN, Form::MAX, Form::RANGE], TRUE) && in_array($input->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], TRUE) ) { diff --git a/tests/Forms/Controls.translate().phpt b/tests/Forms/Controls.translate().phpt index 27a7a8cbf..f02ecd648 100644 --- a/tests/Forms/Controls.translate().phpt +++ b/tests/Forms/Controls.translate().phpt @@ -83,13 +83,13 @@ test(function () { $email = $form->addText('email') ->addRule($form::EMAIL, 'error'); - Assert::match('', (string) $email->getControl()); + Assert::match('', (string) $email->getControl()); $email->validate(); Assert::same(['error'], $email->getErrors()); $email2 = $form->addText('email2') ->addRule($form::EMAIL, new StringWrapper('Your name')); - Assert::match('', (string) $email2->getControl()); + Assert::match('', (string) $email2->getControl()); $email2->validate(); Assert::same(['StringWrapper'], $email2->getErrors()); }); diff --git a/tests/Forms/Forms.renderer.1.expect b/tests/Forms/Forms.renderer.1.expect index 354573029..b9fa8fec9 100644 --- a/tests/Forms/Forms.renderer.1.expect +++ b/tests/Forms/Forms.renderer.1.expect @@ -14,7 +14,7 @@ - + Enter your age diff --git a/tests/Forms/Forms.renderer.2.expect b/tests/Forms/Forms.renderer.2.expect index 09ccd5ac5..79d658751 100644 --- a/tests/Forms/Forms.renderer.2.expect +++ b/tests/Forms/Forms.renderer.2.expect @@ -13,7 +13,7 @@
-
• +
Age must be numeric value