- Deprecate first block argument in save. It's new signature is
save { |hash| }
. You already got the form instance when callingform.save
so there's no need to pass it into the block.
Reverting what I did in 1.0.3. Leave your code as it is. You may override a writers like #title=
to sanitize or filter incoming data, as in
def title=(v)
super(v.strip)
end
This setter will only be called in #validate
.
Readers still work the same, meaning that
def title
super.downcase
end
will result in lowercased title when rendering the form (and only then).
The reason for this confusion is that you don't blog enough about Reform. Only after introducing all those deprecation warnings, people started to contact me to ask what's going on. This gave me the feedback I needed to decide what's the best way for filtering incoming data.
- Systematically use
fields
when saving the form. This avoids calling presentational readers that might have been defined by the user.
-
The following property names are reserved and will raise an exception:
[:model, :aliased_model, :fields, :mapper]
-
You get warned now when overriding accessors for your properties:
property :title def title super.upcase end
This is because in Reform 1.1, those accessors will only be used when rendering the form, e.g. when doing
= @form.title
. If you override the accessors for presentation, only, you're fine. Addpresentation_accessors: true
to any property, the warnings will be suppressed and everything's gonna work. You may removepresentation_accessors: true
in 1.1, but it won't affect the form.However, if you used to override
#title
or#title=
to manipulate incoming data, this is no longer working in 1.1. The reason for this is to make Reform cleaner. You will get two options:validate_processor
and:sync_processor
in order to filter data when calling#validate
and when syncing data back to the model with#sync
or#save
.
-
Deprecated model readers for
Composition
andActiveModel
. Consider the following setup.class RecordingForm < Reform::Form include Composition property :title, on: :song end
Before, Reform would allow you to do
form.song
which returned the song model. You can still do this (but you shouldn't) withform.model[:song]
.This allows having composed models and properties with the same name. Until 1.1, you have to use
skip_accessors: true
to advise Reform not to create the deprecated accessor.Also deprecated is the alias accessor as found with
ActiveModel
.class RecordingForm < Reform::Form include Composition include ActiveModel model :hit, on: :song end
Here, an automatic reader
Form#hit
was created. This is deprecated asThis is gonna be removed in 1.1.
- Removed
Form::DSL
in favour ofForm::Composition
. - Simplified nested forms. You can now do
validates :songs, :length => {:minimum => 1} validates :hit, :presence => true
- Allow passing symbol hash keys into
#validate
. - Unlimited nesting of forms, if you really want that.
save
gets called on all nested forms automatically, disable withsave: false
.- Renaming with
as:
now works everywhere. - Fixes to make
Composition
work everywhere. - Extract setup and validate into
Contract
. - Automatic population with
:populate_if_empty
in#validate
. - Remove
#from_hash
and#to_hash
. - Introduce
#sync
and make#save
less smart.
- Last release supporting Representable 1.7.
- In ActiveModel/ActiveRecord: The model name is now correctly infered even if the name is something like
Song::Form
.
- Maintenance release cause I'm stupid.
- Allow proper form inheritance. When having
HitForm < SongForm < Reform::Form
theHitForm
class will containSongForm
's properties in addition to its own fields. ::model
is now inherited properly.- Allow instantiation of nested form with emtpy nested properties.
- Accessors for properties (e.g.
title
andtitle=
) can now be overridden in the form and callsuper
. This is extremely helpful if you wanna do "manual coercion" since the accessors are invoked in#validate
. Thanks to @cj for requesting this. - Inline forms now know their class name from the property that defines them. This is needed for I18N where
ActiveModel
queries the class name to compute translation keys. If you're not happy with it, use::model
.
#form_for
now properly recognizes a nested form when declared using:form
(instead of an inline form).- Multiparameter dates as they're constructed from the Rails date helper are now processed automatically. As soon as an incoming attribute name is
property_name(1i)
or the like, it's compiled into a Date. That happens inMultiParameterAttributes
. If a component (year/month/day) is missing, the date is considerednil
.
- Fix a bug where
form.save do .. end
would callmodel.save
even though a block was given. This no longer happens, if there's a block to#save
, you have to manually save data (ActiveRecord environment, only). #validate
doesn't blow up anymore when input data is missing for a nested property or collection.- Allow
form: SongForm
to specify an explicit form class instead of using an inline form for nested properties.
ActiveRecord::i18n_scope
now returnsactiverecord
.Form#save
now calls save on the model inActiveRecord
context.Form#model
is public now.- Introduce
:empty
to have empty fields that are accessible for validation and processing, only. - Introduce
:virtual
for read-only fields the are like:empty
but initially read from the decorated model. - Fix uniqueness validation with
Composition
form. - Move
setup
andsave
logic into respective representer classes. This might break your code in case you overwrite private reform classes.
- Added nested property and collection for
has_one
andhas_many
relationships. . Note that this currently works only 1-level deep. - Renamed
Reform::Form::DSL
toReform::Form::Composition
and deprecatedDSL
. require 'reform'
now automatically requires Rails stuff in a Rails environment. Mainly, this is the FormBuilder compatibility layer that is injected intoForm
. If you don't want that, only require 'reform/form'.- Composition now totally optional
Form.new
now accepts one argument, only: the model/composition. If you want to create your own representer, inject it by overridingForm#mapper
. Note that this won't create property accessors for you.Form::ActiveModel
no longer creates accessors to your represented models, e.g. havingproperty :title, on: :song
doesn't allowform.song
anymore. This is because the actual model and the form's state might differ, so please useform.title
directly.
- Altered
reform/rails
to conditionally loadActiveRecord
code and createdreform/active_record
.
Form#to_model
is now delegated to model.- Coercion with virtus works.
- Added
reform/rails
that requires everything you need (even in other frameworks :). - Added
Form::ActiveRecord
that gives youvalidates_uniqueness_with
. Note that this is strongly coupled to your database, thou. - Merged a lot of cleanups from sweet @parndt <3.
- Oh yeah.