Skip to content
Advertisement

Error with Symfony The option “constraints” does not exist

Symfony question, I’m just starting to learn it. The user uploads a file with data that I want to submit to the form for validation in the form of an array (key-value). I call the method to build the form, pass an array there and try to check, for example, that the length of the title (‘title’) is no more than 255 characters. The error “The option “constraints” does not exist” is thrown.

ImportService.php

JavaScript

NewsImportType.php

JavaScript

Error text

An error has occurred resolving the options of the form “SymfonyComponentFormExtensionCoreTypeTextType”: The option “constraints” does not exist. Defined options are: “action”, “allow_file_upload”, “attr”, “attr_translation_parameters”, “auto_initialize”, “block_name”, “block_prefix”, “by_reference”, “compound”, “data”, “data_class”, “disabled”, “empty_data”, “error_bubbling”, “form_attr”, “getter”, “help”, “help_attr”, “help_html”, “help_translation_parameters”, “inherit_data”, “invalid_message”, “invalid_message_parameters”, “is_empty_callback”, “label”, “label_attr”, “label_format”, “label_html”, “label_translation_parameters”, “mapped”, “method”, “post_max_size_message”, “priority”, “property_path”, “required”, “row_attr”, “setter”, “translation_domain”, “trim”, “upload_max_size_message”.

ALTERNATIVE SOLUTION

Add ‘FormFactoryInterface $formFactory’ to the constructor. And in the method itself, fix to ‘$this->’

JavaScript

Advertisement

Answer

The constraints option is part of ValidatorExtension and it is not part of core form extensions. You can use it like following

JavaScript

also add this

JavaScript

refer link for details

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement