10

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?

Dave Sag
  • 13,266
  • 14
  • 86
  • 134
  • [Does this help?](https://github.com/slim-template/slim/issues/198) – Mike Aug 01 '13 at 02:17
  • 1
    No. See https://github.com/slim-template/slim/issues/433 – Dave Sag Aug 01 '13 at 02:36
  • 1
    Actually [this answer](https://github.com/slim-template/slim/issues/433#issuecomment-21923391) pretty much nails it. Apparently attribute="" is equivalent to the standalone attribute, so slim is correct. It seems to be a bug in the Zurb Foundation framework, or, more likely, some error in my own. – Dave Sag Aug 01 '13 at 11:36
  • My solution has been to drop using Zurb Foundation and port my app to Bootstrap 3 – Dave Sag Aug 02 '13 at 05:08

3 Answers3

4

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="">
Cumulo Nimbus
  • 8,785
  • 9
  • 47
  • 68
1

More readable would be:

= f.input :email, required: true, autofocus: true
The Whiz of Oz
  • 6,763
  • 9
  • 48
  • 85
0

Use this:-

= text_field_tag :user_name, "XYZ", readonly: true, required: true