avo icon indicating copy to clipboard operation
avo copied to clipboard

Automatically determine required fields from validations

Open iainbeeston opened this issue 3 years ago • 1 comments
trafficstars

Feature

Right now, to mark a field as required you have to explicitly add the required: true to the field declaration in the resource class. Simple form does this automatically by looking at the validations on the model (see the code here). It would be great if avo could do this too (if required: is not set in the resource)

Current workarounds

The only way to do this right now is to manually keep the validations in the model and resource definition in sync, but it is a lot of work and I'm not sure that anyone could do that reliably

Screenshots

Additional context

Here is the code that simple form uses:

  • https://github.com/heartcombo/simple_form/blob/86429bceb950096df3c29616f31bd5a5ce706c06/lib/simple_form/helpers/required.rb
  • https://github.com/heartcombo/simple_form/blob/86429bceb950096df3c29616f31bd5a5ce706c06/lib/simple_form/helpers/validators.rb

iainbeeston avatar Jun 17 '22 16:06 iainbeeston

Great idea. I'll have a look over that snippet and add it to the roadmap.

adrianthedev avatar Jun 17 '22 16:06 adrianthedev

I was pointed to this issue on the discord server. I think it'd be fantastic for required to be inferred based on the model/validations, but I think the required field should also continue to be overridable such that we can force it to be required (or not) in Avo.

rickychilcott avatar Aug 17 '22 10:08 rickychilcott

Also, this feels like a nice first issue so @iainbeeston, if you want to take a stab, that'd be super cool!

https://github.com/avo-hq/avo/pull/955 might help get you started in seeing where to hook in and make this happen.

rickychilcott avatar Aug 17 '22 10:08 rickychilcott