LoginSignup
16
9

More than 5 years have passed since last update.

Rails5.1 + Bootstrap4でfield_with_errors

Posted at

field_with_errorsクラスとは?

Railsのバリデーションでエラーになった箇所に付与されるクラスの事です。
Workman.png

Bootstrap3

  • field_with_errorsクラスに対して Bootstrap3の .has-error をextendすることで入力欄が赤枠で表示されていた。
application.scss
.field_with_errors {
  @extend .has-error;
}

Bootstrap4

  • .has-error が無くなっているのでextendできない。
  • 代わりに input タグに対して .is-invalid をextendする。
application.scss
.field_with_errors {
  input {
    @extend .is-invalid;
  }
}
16
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
9