Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foundation 6 with Rails Simple Form

Simple Form includes a Foundation 5 template.

However, I cannot find any template files modified for Foundation 6 on the web.

How well does the generated forms work with Foundation 6? Moreover, any generous share of Foundation 6 template or tips on modifying the existing template?

like image 270
Gavin Avatar asked Mar 21 '16 11:03

Gavin


People also ask

What is simple form rails?

Rails forms made easy. Simple Form aims to be as flexible as possible while helping you with powerful components to create your forms. The basic goal of Simple Form is to not touch your way of defining the layout, letting you find the better design for your eyes.

How do you add classes in simple form?

It's not possible to customize it, SimpleForm add the dom class automatically based on the given object. What you can do is to add more classes by giving the :html => {:class => "bar"} option.

How to create a form in rails?

If you have done any HTML, then this one is the simplest and the most straightforward way of creating a form in Rails. Here the form is created with the usual HTML markup. In such a form you define everything by yourself and don't take any help from Rails. You have to declare method="post" and set the form submission route action="/users" yourself.

How do I create a form in Foundation?

Creating a form in Foundation is designed to be easy but extremely flexible. Forms are built with a combination of standard form elements, as well as grid rows and columns or cells. These input types create a text field: text, date, datetime, datetime-local, email, month, number, password, search, tel, time, url, and week.

What is a form params in rails?

In simple words params contain some information about the incoming request. What Rails does is that it sets up user hash inside of the params hash and inside the user hash it sets up all the form name, value pairs. When the form is submitted it takes all the form values, stuffs them in the user hash of the params hash and sends it to the server.

How to pre-fill a form with value?

The "Rails way" to pre-fill the form with value is to use a Model, which is an object mixed to the database. If you already have some coding experience, that sounds wrong. Actually, many tutorials do not advise to do so. Instead, you use a plain Model, not mapped to the database, named "form object".


2 Answers

I am not sure if simple_form can be configured to provide what Foundation 6 requires for fields with errors.

Until I can figure that out (if, if, if), I have this hack in place using Sass @extend:

// TODO: This is a hack to get Foundation 6 styles on simple_form 
// elements with errors.
.input.error {
  label {
    @extend .is-invalid-label;
  }

  input,
  textarea,
  select {
    @extend .is-invalid-input;
  }

  small.error {
    @extend .form-error;
    @extend .is-visible;
  }
}

Are you dissatisfied with this answer? I am too. I hope that someone can "show me up" on this with a better answer.

like image 100
Chris Peters Avatar answered Nov 02 '22 03:11

Chris Peters


Just a little progress, you can set in config file simple_form.rb this:

config.wrappers .... do |c|
  ...  
  c.use :error, wrap_with: { tag: :small, class: 'form-error is-visible'
  ..
end   

and error messages will be formatted .. However, I did not find solution for labels and inputs, so the @Chris's solution for labels and inputs is still needed. However, if you don't need red labels and inputs, this is sufficient

like image 43
Lubomir Vnenk Avatar answered Nov 02 '22 05:11

Lubomir Vnenk