Data-confirm and data-disable in forms

Is it possible to implement data-confirm in a form, similar to how you can in a link?

I tried the following, but it doesn’t work.

<%= form_for @changeset, @action, fn f -> %>
  # other code removed
    <%= submit "Submit", class: "btn btn-primary", data: [confirm: "Really?"] %>
<% end %>

I know with a link you can use code like this:

<%= link "Delete", to: fantasy_team_path(@conn, :delete, fantasy_team), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %>

Can you use a link instead of submit within your form? Or is there another way to implement it? I would also like to implement data-disable in my form, if that is possible.

Thanks for any help you can provide!


I think it only works for <a>elements, see source code here

I just use a modal and it works nicely… there are many html5/css/js frameworks that provide them with little fuss.

For example foundation modal

You can easily do your own just by adding a javascript event handler inline. Look at the source for link to see how it does it. :slight_smile:

1 Like

Try using data-submit="parent". If that works, let me know and I will document it as a feature. We use it internally for other features, I never thought it could be a feature on its own. :slight_smile: Source:


Thanks, I was able to get data-submit="parent" to work!

1 Like

What about the data-disable? is there a way to have a read only data field in a form?
Thank you :slight_smile: