avo-hq / avo

Build Ruby on Rails apps 10x faster

Home Page:https://avohq.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add hard required on (action) form input

pjmuller opened this issue · comments

Feature

Within the action fields we can add required: true but as required field option documentation points out, this is only cosmetic.

class Avo::Actions::FooBar < Avo::BaseAction
  def fields
    field :my_text, as: :text, required: true
 end    

This means anyone can submit the form while the browser could perfectly give some initial validation feedback.
Sidenote: this does not only apply to actions (also to the record edit forms), but is especially useful in actions as you don't have ActiveRecord validation that will automatically display upon submitting of the form -> meaning you need to add a lot more boilerplate in the handle method

Current workarounds

part 1: proactive (not working yet)

Not working yet, but if we can extend html field option on top of style, classes, and data to also allow for required?

field :my_text, as: :text, required: true, 
      html: {
        edit: {
          input: {
            required: "true"
          }
        }
      }

part 2: reactive (already working)

use keep_modal_open

def handle(fields:, **args)
    if params[:my_text].blank
       error "Something happened: #{error.message}"
       keep_modal_open  
       return
    end
   # ...
  end

Screenshots or screen recordings

Screenshot 2024-05-23 at 17 56 37

This issue has been marked as stale because there was no activity for the past 15 days.