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?
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}
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'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With