trailblazer / reform

Form objects decoupled from models.
https://trailblazer.to/2.1/docs/reform.html
MIT License
2.49k stars 184 forks source link

Coerced values remain in the form when rerendering the view on failed validation #450

Open bolstycjw opened 6 years ago

bolstycjw commented 6 years ago

Complete Description of Issue

When using coercion with Reform, the raw date strings are coerced into Date types during validation. If validation fails, the values remain as the coerced types. This results in incorrect date format display when the form is rerendered on the view.

Steps to reproduce

class FooForm < Reform::Form
  feature Coercion

  property :date, type: Types::Form::Date

  validation do
    required(:date).filled(:date?)
  end
end

Expected behavior

Reform should revert the form values to their original raw input when validation fails.

Actual behavior

Form values are persisted in the form object even if validation fails and input is invalid.

System configuration

Reform version: 2.2