I am trying to add the boolean attribute "novalidate" to all my forms.
I have tried numerous approaches in my theme_preprocess_form function but no luck. I see in some preprocess functions, $variables['attribute'] is an object and has methods like addClass() and setAttribute(). But in _preprocess_form it is an array. Plus setAttribute doesnt sound like it will do boolean attributes anyway.
I tried to simply override the twig template for a form and do this:
<form{{ attributes }} novalidate>
{{ children }}
</form>
but even that outputs:
<form novalidate="">
novalidate=""
is fine for the HTML spec - boolean attributes can have a value as long as it's an empty string or the same (case-insensitive) string as the attribute name. Sonovalidate="novalidate"
would also be fine. If you follow those rules, the attribute's existence is taken to meantrue
regardless of the value. See developer.mozilla.org/en-US/docs/Web/HTML/…novalidate
, even though it doesn't technically matter? Probably over-thinking it, I'll add an answer<form novalidate="">
, but it is in fact still<form novalidate>
. You can use the ancient method of viewing the source ("View Page Source" in Firefox and Google Chrome) to see the actual HTML markup.