constraint-validation-example

Expand History Expand History
Collapse History Collapse History

Abstract Validation Message rendering

Declare ValidationMessageFormBuilder#validation_message to combine all of the newly introduced FormBuilder concepts:

For fields without any errors, do nothing and render nothing.

When a field has any errors for the attribute, create an instance of ActionView::Helpers::TagHelper#tag that is pre-built with the correct DOM [id] attribute, generated by validation_message_id.

When passed block, yield the collection of ActiveModel::Error instances along with the pre-built tag. The calling block is responsible for building an element to contain the validation messages.

When a block is not given, render a <span> element with the pre-built tag instance.

In either case, pass along any attributes passed as part of the options.