Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set HTML5 attributes like 'required' using a Slim template

I m laying out a form using the Slim template language and want to add the required attribute to my input.

input#first_name(required name="first_name" type="text" pattern="^[A-Z][a-z]+$")

However the HTML that is generated from this ends up being

 <input id="first_name" name="first_name" pattern="^[A-Z][a-z]+$" required="" type="text" />

And that's not what I need.

I've gone through the docs but can't see any way with Slim to add a standalone html5 attribute.

Likewise adding the data-abide attribute to the form tag (as required by the Zurb Foundation framework) fails.

form.custom(data-abide method="POST" action="/registration")

leads to

<form action="/registration" class="custom" data-abide="" method="POST">

Which the Zurb scripts ignore.

What am I missing?

like image 724
Dave Sag Avatar asked Aug 01 '13 02:08

Dave Sag


People also ask

What is slim template?

Slim is a template language whose goal is to reduce the view syntax to the essential parts without becoming cryptic. It started as an exercise to see how much could be removed from a standard html template (<, >, closing tags, etc...).

What is HTML slim?

What's Slim? Slim is a page-templating language that minimizes markup and syntax. It removes most of the extra "programming-like" symbols from HTML so that your code looks cleaner. Slim also adds if-else statements, loops, includes, and more.


2 Answers

In your *.html.slim file do:

input#first_name required="" name="first_name" type="text" pattern="^[A-Z][a-z]+$"

Note that empty attribute syntax:

<input required>

Is equivalent to:

<input required="">
like image 155
Cumulo Nimbus Avatar answered Oct 29 '22 09:10

Cumulo Nimbus


More readable would be:

= f.input :email, required: true, autofocus: true
like image 32
The Whiz of Oz Avatar answered Oct 29 '22 08:10

The Whiz of Oz