Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Adjust Size of Form Fields

Started by Muut Archive 10 years ago · 7 replies · 1496 views
10 years ago

What do I have to do for the field size to work in forms? It's always big although there are four options. Valid values are large, x-small, medium, long, small. None of them work. Do I have to configure something?

10 years ago

They work for admin forms. Do you ask it for frontend forms?

10 years ago

Yeah for the frontend forms. For instance, the contact page in the deliver skeleton: http://demo.getgrav.org/deliver-skeleton/contact. The textarea of name and email has been resized. I want to do the same. How can I achieve that? It always takes all the wide of the page. I was checking the code but can't figure it out. It looks like there are some cached classes ... I don't get it.

10 years ago

In that particular case, the size is set via CSS using

CSS
.contact input {
    width: 50%;
}
.contact textarea {
    width: 80%;
}

You can do the same by adding a class in the form field definition

YAML
form:
    name: ...

    fields:
        - name: name
          ....
          classes: large 

and then adding some styling in your own theme or using https://github.com/getgrav/grav-plugin-custom-css

10 years ago

Where is located the code of these classes? In the deliver skeleton we have for example: form-control form-control-lg. I searched the whole project to find these classes. I just saw some code inside cache sub directories: "/cache/twig/1a/(long number).php". If I should add these classes in my own customized theme, where should I put them?

10 years ago

You define them. For the frontend, there is nothing "predefined" and the theme might implement a particular class, or not.

Just add the class to the form definition, and it will create the form field HTML markup with that class.

Then add some CSS via the plugin I linked, to make it smaller or longer.

10 years ago

OK I did it. It works. Thank you flaviocopes. I added the class and customize it in a new file: "/user/themes/antimatter/css/custom.css". The antimatter theme was already pulling the css configuration from that file. It just needed to be created. I'm new to twig and templating engines. That's why I got confused.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1369 9 years ago
Archive · by Muut Archive, 9 years ago
2 942 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago