leastbad / optimism

The missing drop-in solution for realtime remote form validation in Rails.
MIT License
361 stars 42 forks source link

Attribute name overrides #17

Closed Inkybro closed 4 years ago

Inkybro commented 4 years ago

This is my attempt at some functionality including that described in #15

I just wanted to take a quick crack at it, so this may not at all be usable, and it may introduce more problems than it solves, I'm not sure.

Let me know what you think, @leastbad (or anyone!) Looking forward to some feedback.

P.S. Sorry, went a little haywire on the code :P


Usage example:

broadcast_errors @account, account_params, email_attributes: { address: 'Email address' }, mobile_attributes: { number: false }

This results in messages like Email address can't be blank for email_attributes[:address], and can't be blank for mobile_attributes[:number].

Inkybro commented 4 years ago

I just realized that the behavior I was looking for already exists via I18n. I've never really messed much with localization so I wasn't aware of this lol. This ended up being a nice learning experience.

Still, we could add a raw_messages option for those who need it. I'd be happy to open a new PR if desired, just let me know!