Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Add validations or awareness of validations #65

Open
@sfcgeorge

Description

@sfcgeorge

Validations being server only is ok as you have single source of truth, and saving is so fast and easy you can display feedback pretty quick, the errors come through as it is and can be displayed in form inputs. Nonetheless having live frontend validations could be nice, at least for some field types.

One motivation is creating smart form components. It's common to put a red * asterisk next to required fields, it would be nice if the form input components could figure that out from the model automatically.

I'd suggest 2 steps:

Read-only validations

Replicate the validations APIs that allow you to query which validators have been added to which attributes.

This metadata allows creation of smart input components over in hyper-react that query the record's validators in order to display asterisk next to required field, perhaps even add HTML5 validation attributes, etc.

This is how you would do the "required" asterisk:

MyModel.validators_on(:some_attribute).any? do |validator| 
  validator.kind_of?(ActiveModel::Validations::PresenceValidator)
end

Working validations

For live validating as you type, pre-validation before you save, whatever. Would probably want to be optional. Lots of work though and may not be worth it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions