nextras / form-components

Form components for Nette Framework (architecture & UI components)
Other
11 stars 3 forks source link

Problem with BaseControlTrait in my class extending Nette\Forms\Controls\TextInput #7

Closed mprof closed 2 years ago

mprof commented 2 years ago

When using Nextras\FormComponents\Fragments\Traits\BaseControlTrait in my class representing live form server validation, then occours error with method getControl() (origin in BaseControlTrait):

TypeError: Nette\Forms\Helpers::exportRules(): Argument #1 ($rules) must be of type Nette\Forms\Rules, null given

Seems like $this->rules variable is empty, when using this trait.

1269EAA2E1FC4D97BA1BA55DCB3F2DF3

hrach commented 2 years ago

What is the namespace of the TextInput you inherit from? Since if you are using https://github.com/nextras/form-components/blob/master/src/Fragments/UIControl/TextInput.php you shouldn't use traits.

mprof commented 2 years ago

What is the namespace of the TextInput you inherit from? Since if you are using https://github.com/nextras/form-components/blob/master/src/Fragments/UIControl/TextInput.php you shouldn't use traits.

Namespace of inherited TextInput is: Nette\Forms\Controls (like in your solution)

I am trying to reproduce your solution posobota-2014-server-validation in actual version of Nette, so everything is almost same, but when use BaseControlTrait, described error occurs.

hrach commented 2 years ago

well, that's 8 years old. things changed since then. you may take a look at https://github.com/nextras/form-components/blob/master/src/Controls/AutocompleteControl.php how to inherit from text field.