1

I used Assert to validate fields like

@Assert\NotBlank(message="this field cannot be empty")
$private title;

@Assert\NotBlank(message="this field cannot be empty")
$private description;

@Assert\NotBlank(message="this field cannot be empty")
$private price;

Now, when Im using form in html.twig

{% body block %}
{{ form(form, {"attr": {"novalidate": "novalidate"}}) }}
{% endblock %}

everything is allright, if I have an empty field I got my message, but when Im trying to divide this form like

{% body block %}

{{ form_start(form, {"attr": {"novalidate": "novalidate"}}) }}
{{ form_widget(form.title) }}
{{ form_widget(form.description) }}
{{ form_widget(form.price) }}
{{ form_rest(form) }}
{{ form_end(form, {"attr": {"novalidate": "novalidate"}}) }}

{% endblock %}

I'm getting something like default message that I cannot add an advert, but there are no messages next to my fields. What am I doing wrong?

I've tried use novalidate attribute in every form field but it still doesn't working

1 Answer 1

4

You should use {{ form_row(form.title) }} instead {{ form_widget(form.title) }} and so on. Alternatively add {{ form_error(form.title) }} to every {{ form_widget(form.title) }} and so on.

Explanation: form_widget render only form control ie. input box or drop-down. form_row render: form_label - the title of field, form_widget - the control, form_error if needed - the errors attached to field. It also wrap everything on nice div to group related parts.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I'll be at home for few hours and I will check this solution, thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.