Skip to content

Instantly share code, notes, and snippets.

@raderj89
Created March 4, 2014 19:44
Show Gist options
  • Save raderj89/9354083 to your computer and use it in GitHub Desktop.
Save raderj89/9354083 to your computer and use it in GitHub Desktop.
%h2 New Project
= form_for(@project) do |f|
%div{ id: "error_explanation" }
- if @project.errors.any?
%h2= pluralize(@project.errors.count, "error")
Prohibited this project from being saved:
%ul
- @project.errors.full_messages.each do |msg|
%li= msg
%p
= f.label :name
%br
= f.text_field :name
%p
= f.label :description
%br
= f.text_field :description
= f.submit
@raderj89
Copy link
Author

raderj89 commented Mar 4, 2014

My problem:

You can see that the label and fields are wrapped in <p> tags. However, when I submit a form with an error, it wraps the labels in <div id="field_with_errors"> and leaves me with empty <p> tags:

<form accept-charset="UTF-8" action="/projects" class="new_project" id="new_project" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value=""><input name="authenticity_token" type="hidden" value="MxPiICrF13JUCGOOVdbrRtrUmMirFE37KqwkM+XEznw="></div>  <div id="error_explanation">
        <h2>1 error</h2>
        Prohibited this project from being saved:
        <ul>
          <li>Name can't be blank</li>
        </ul>
      </div>
      <p>
        </p><div class="field_with_errors"><label for="project_name">Name</label></div>
        <br>
          <div class="field_with_errors"><input id="project_name" name="project[name]" type="text" value=""></div>
        <br>
      <p></p>
      <p>
        <label for="project_description">Description</label>
        <br>
          <input id="project_description" name="project[description]" type="text" value="">
        <br>
      </p>
      <input name="commit" type="submit" value="Create Project">
    </form>

@beaugaines
Copy link

Is indentation accurate here? Your labels and inputs should be on the same level. If that don't help maybe wrap the label/inputs in fieldsets or divs? Not sure, never experienced this problem myself...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment