Skip to content

Using Nette\Utils\Html as label with validation causes: rtrim() expects parameter 1 to be string, object given #234

Description

@JanMikes

Version: 3.0.1

Bug Description

When using Nette\Utils\Html as caption/label for input, it will fail on TypeError in validator. This code worked in 2.4

Screenshot 2019-11-18 10 45 57

Steps To Reproduce

$label = \Nette\Utils\Html::el()->setHtml('<i>Demo</i>');
        
$form->addText('demo', $label)
    ->setRequired('Please fill in %label.');

Expected Behavior

To not throw exception and return (string) $html in %label placeholder.

Possible Solution

This fix worked for us:

+                   $caption = $rule->control->getCaption();
                    return $rule->control instanceof Controls\BaseControl
-                        ? rtrim($rule->control->translate($rule->control->getCaption()), ':')
+                        ? $caption instanceof Nette\Utils\Html ? $caption : rtrim($rule->control->translate($caption), ':')
                        : null;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions