ruby-hyperloop / hyper-mesh

The project has moved to Hyperstack!! - Synchronization of active record models across multiple clients using Pusher, ActionCable, or Polling
https://hyperstack.org/
MIT License
22 stars 12 forks source link

Add validations or awareness of validations #65

Open sfcgeorge opened 6 years ago

sfcgeorge commented 6 years ago

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.

catmando commented 6 years ago

Good idea... i think its doable, I don't think we should put on 1.0 release path, unless everybody thinks so...

sfcgeorge commented 6 years ago

Na I agree not adding anything big and new for 1.0, mainly refining.