Skip to content

add hard required on (action) form input #2803

Open
@pjmuller

Description

@pjmuller

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNot necessarily a feature, but something has improvedHelp wantedWe could use some help with this

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions