EastsideDev
EastsideDev

Reputation: 6639

Login form not displaying as expected

Here's what I have in views/users/sessions/new.html.slim

.container
  = form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: "form-signin"}) do |f|
    h2.form-signin-heading
      = t('users.mailer.registrations.sessions.new.please_sign_in')
    .sr-only
      = f.label t('users.sessions.new.email_address')
      br/
    .form-control.email_input
      = f.email_field :email, autofocus: true, placeholder: "#{t('users.sessions.new.email_address')}", required: ""
      br/
    .sr-only
      = f.label t('users.sessions.new.password')
      br/
    .form-control.password_input
      = f.password_field :password, autofocus: true, placeholder: "#{t('users.sessions.new.password')}", required: ""
      br/
    - if devise_mapping.rememberable?
      .checkbox
        label
          = f.check_box :remember_me
          = t('users.sessions.new.remember_me')
    = f.submit t('users.mailer.sessions.new.log_in'), class: "button.btn.btn-lg.btn-primary.btn-block"
    .form-group
      .col-md-offset-4.col-md-8
       = render "devise/shared/links"

Here's what I have in assets/stylesheets/signin.css.scss:

.form-signin {
  max-width: 330px;
  padding: 15px;
  margin: 0 auto;
}
.form-signin body {
  padding-top: 40px;
  padding-bottom: 40px;
  background-color: #ee
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
  text-align: center;
  margin-bottom: 10px;
}
.form-signin .checkbox {
  font-weight: normal;
}
.form-signin .form-control {
  position: relative;
  height: auto;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  padding: 10px;
  font-size: 16px;
}
.form-signin .form-control:focus {
  z-index: 2;
}
.form-signin .email_input {
  margin-bottom: -1px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
}
.form-signin .password_input {
  margin-bottom: 10px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}   

and I've imported this stylesheet in my application.css.scss

In my en.yml, I have:

    users:
      sessions:
        new:
          please_sign_in: "Please Sign In"
          password: "Password"
          log_in: "Log In"
          email_address: "Email Address"
          remember_me: "Remember Me"    

Here's what I see:

My Results

Here's what I am expecting to see:

Expected results

I am new to scss. Any idea that can help me diagnose the problem?

I made the following change:

.sr-only
  = f.label t('users.sessions.new.email_address')
.form-group
  = f.email_field :email, class: 'form-control form-signin email_input', autofocus: true, placeholder: "#{t('users.sessions.new.email_address')}", required: ""
.sr-only
  = f.label t('users.sessions.new.password')
.form-group
  = f.password_field :password, class: 'form-control form-signin password_input', autofocus: true, placeholder: "#{t('users.sessions.new.password')}", required: ""

and I now have:

My results 2

But the placeholder text is not showing, and the login button is not right

Upvotes: 0

Views: 23

Answers (1)

user229044
user229044

Reputation: 239311

The form-control class goes directly on the input elements, no on their containers. The containers are supposed to have a class of form-group.

This...

.form-control.email_input
    = f.email_field :email, autofocus: true, placeholder: "#{t('users.sessions.new.email_address')}", required: ""

... should be something along the lines of:

.form-group
  = f.email_field, class: 'form-control', ...

Upvotes: 1

Related Questions