I'm using garlic.js to validate my forms. Garlic.js recommends adding a data-attribute on the form tag.
Here's what I need to generate:
<form data-validate="parsley">
I'm having issues to generate this data attribute on the form tag. I tried everything and nothing worked. Anyone has a solution to this?
Try this:
<%= simple_form_for @entity, :html => {:"data-validate" => 'parsley'} do |f| %>
<!-- inputs -->
<% end %>
Update
From the comment below, to have the form include an HTML5 data attribute with no value try the following:
<%= simple_form_for @entity, :html => {:"other-data-value" => ''} do |f| %>
By setting the attribute to an empty string the form helper renders just the attribute.
You can set data attributes directly by passing in a data hash, but all other HTML options must be wrapped in the HTML key. Example:
<%= form_for(@post, data: { validate: "parsley" }, html: { name: "go" }) do |f| %>
...
<% end %>
The HTML generated for this would be:
<form action='http://www.example.com' method='post' data-validate='parsley' name='go'>
...
</form>
api.rubyonrails.org
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