Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

required input in activeadmin form not working

I am using active_admin. I am trying to make a form field required in activeadmin:

  input :team, as: :select, required: true, collection: Team.all.pluck(:name, :id), include_blank: "Please enter a team", allow_blank: false

It is only on this specific activeadmin page that i want this validation. It should not exist anywhere else in the site, so I don't want to do it in the model.

For some reason, the code above is not working. While the form field does show a *, it still submits. How can I make this input required only on this page?

like image 925
Philip7899 Avatar asked Jul 13 '17 17:07

Philip7899


2 Answers

What you need is input_html: {required: true}

# adds .required class to the input's enclosing <li> element - form can still be submitted
input :team, required: true   

# adds required attribute to the <input> element - form cannot be submitted
input :team, input_html: {required: true} 
like image 131
AFOC Avatar answered Nov 18 '22 14:11

AFOC


This is really a Formtastic issue, not Active Admin. I don't think you can combine allow_blank: false, include_blank: 'text' and required: true. Try include_blank: false and hint: 'Please enter a team'.

like image 29
Piers C Avatar answered Nov 18 '22 14:11

Piers C