Customize text_area Ruby on rails to Materialize css - css

Im trying to customise the "<%= f.text_area :content %>" in rails 5.0.
To a text_area that materialize has like this one
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s6">
<i class="material-icons prefix">mode_edit</i>
<textarea id="icon_prefix2" class="materialize-textarea"></textarea>
<label for="icon_prefix2">First Name</label>
</div>
</div>
</form>
</div>
The problem is that I tried to figure it out on how to insert the default text_area that I have in to this one, erasing the ugly box the I have to type a text. (I'm a bit fancy)
This is my form:
<%= form_for(#micropost, html: { multipart: true }) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.text_area :content %> >>>>>>#This is the one I want to change
<%= f.submit "Post", class: "waves-effect waves-light btn green accent-3 z-depth-4" %>
<span class="picture">
<%= f.file_field :picture, accept: 'image/jpeg,image/gif,image/png' %>
</span>
<% end %>
This is what I tried:
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s6">
<i class="material-icons prefix">mode_edit</i>
<textarea id="icon_prefix2" class="materialize-textarea"><%= f.text_area :content %></textarea>
<label for="icon_prefix2">First Name</label>
</div>
</div>
</form>
</div>
But i'm unlucky to make it work, and I tried many other ways that I haven't figure out how to customise this feature to my app.
I spend to much time figuring out on how to erase that box and put a single fancy line style materialize way.
I will appreciate too much you help!

What's the problem you have?, you just need to add the corresponding class:
<%= f.text_area :content id: 'icon_prefix2', class: 'materialize-textarea' %>

Related

How format Rails form field with CSS/Bootstrap?

I've tried a lot of research and tinkering and I just can't get my Rails view to format a form with Bootstrap or CSS. I know that the Bootstrap classes could be affecting it or the CSS.
What I'm trying to do is just create a two column, side by side container. With an image in one column next to the form in the other. Both the same size.
I've tried the expected and researched:
Container with row with two columns. One column as the form and the second column as the image.
Instead the form is acting like it is fluid and taking up the entire page width and the columns are stacking vertically, instead of side by side.
I want it took look like this:
<div class="container d-flex">
<div class="row">
<div class="col">
<%= form_with(model: car, local: true) do |form| %>
<%= hidden_field_tag "car[login]", exists ? "#{#car.login}" : "#{#current_user.login}" %>
<div class="field">
<%= form.label :model, class: "h3" %><br>
<%= form.text_field :model, id: :car_model, class: "form-control mb-2 mr-sm-2 mb-sm-0" %>
</div>
<div class="field">
<%= form.label :year, class: "h3" %><br>
<%= form.number_field :year, id: :car_year, class: "form-control mb-2 mr-sm-2 mb-sm-0" %>
</div>
<div class="field">
<%= form.label :color, class: "h3" %><br>
<%= form.text_field :color, id: :car_color, class: "form-control mb-2 mr-sm-2 mb-sm-0" %>
</div>
<div class="field">
<%= form.label :licence_plate, class: "h3" %><br>
<%= form.text_field :licence_plate, id: :car_licence_plate, class: "form-control mb-2 mr-sm-2 mb-sm-0" %>
</div>
<div class="actions">
<%= form.button "<h3>#{submit_text}</h3>".html_safe, class: "btn btn-success btn-sm" %>
</div>
<% end %>
<div class="col">
# img source here
</div>
</div>
</div>
</div>
Usually, for bootstrap forms, your label and input should be wrapped by a .form-group element, not a .field one.
https://getbootstrap.com/docs/4.0/components/forms/
Do something like:
<div class="form-group field">
<%= form.label :licence_plate, class: "h3" %><br>
<%= form.text_field :licence_plate, id: :car_licence_plate, class: "form-control mb-2 mr-sm-2 mb-sm-0" %>
</div>

Rails 5: form_for select field tag with select class

I'm currently trying to implement an select_tag, the problem I'm facing is that every css element works, except the select option. Somehow the bootstrap stylesheet gets called when I use f.select :home_type, [["Room", "Room"]], class: 'add-listing__input'
This stylesheet gets called and only select works
http://localhost:3000/assets/triptip-assets.min.self-3157b4719675b23587e706840e28dab5a7506a2794b67521ade419a505a34070.css?body=1
When I use for example f.text_field everything works and this stylesheet gets called
http://localhost:3000/assets/style.self-6fdbeaf8dfea504b6f923ccefbf5f6a7f370c6436cf98feefac201fc92c78f83.css?body=1
EDIT
Here is my form
<%= form_for #room do |f| %>
<div class="add-listing__form-content">
<div class="row">
<div class="col-md-6">
<label class="add-listing__label">
Home Type:
</label>
<%= f.select :home_type, [["Wohngebäude", "Wohngebäude"], ["Bürogebäude", "Bürogebäude"], ["Haus", "Haus"], ["Geschäft", "Geschäft"]], class: 'add-listing__input js-example-basic-multiple' %>
</div>
<div class="col-md-6">
<label class="add-listing__label">
Vacancy Type:
</label>
<%= f.select :vacancy_type, [["Leer", "Leer"], ["Voll", "Voll"]], class: 'add-listing__input js-example-basic-multiple' %>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label class="add-listing__label">
Accomodate:
</label>
<%= f.number_field :accomodate, id: "amount", placeholder: "Für wie viele Personen?", class: "add-listing__input" %>
</div>
<div class="col-md-6">
<label class="add-listing__label">
Abrissgerüchte:
</label>
<%= f.text_field :rumors, id: "rumors", placeholder: "Abrissgerüchte?", class: "add-listing__input" %>
</div>
</div>
</div>
<% end %>
You should define class in select field in this way:
<%= f.select(:vacancy_type, [ ... ], {}, { class: 'my_style_class' }) %>

Simple form and bootstrap incompatible css

I am trying to copy this simple design into edit mode.
Here is the code displaying the image above :
<div class="user-description-container col-md-6 col-md-offset-3">
<div class="col-md-3">
<%= image_tag #user.image.standard.url, class: "user-picture img-circle" %>
</div>
<div class="user-description-box col-md-7">
<div class="user-name"><%= #user.full_name %></div>
<div class="user-stats">
<div class="user-stats-debates inline-flex"><b class="spacing-margin-right">
<%= #user.groups.length %></b><% if #user.groups.length == 0 %>
<p> débat</p><% else %><p> débats</p>
</div>
<% end %>
<div class="user-stats-followers inline-flex"><b class="spacing-margin-right"><%= #user.followers.length %></b> <%if #user.followers.length == 0%>
<p> disciple</p> <% else %><p> disciples</p>
<% end %>
</div>
</div>
<div class="user-description">
<%= #user.description %>
</div>
</div>
<div class="col-md-2 edit-profile">
<% if current_user == #user %>
<%= link_to(edit_user_path(#user),:class =>"edit-button") do %>
<i class="glyphicon glyphicon-pencil"></i>
<% end %>
<% end %>
</div>
</div>
I copied the main design of the page to the edit mode.
Unfortunately, here is what I get :
I am using the simple form gem with rails and I can't get bootstrap working properly. Here is my code on the edit mode :
<div class="container">
<div class="row">
<div class="user-description-container col-md-6 col-md-offset-3">
<%= form_for #user do |form| %>
<div class="user-upload-preview col-md-3">
<%= image_tag #user.image.standard.url, class: "user-picture img-circle object-fit-covered" %>
<div class="form-input">
<label class="btn btn-sm btn-primary image-browse-button" >
Choisir une photo
<span style="display:none;">
<%= form.file_field :image %>
</span>
</label>
</div>
</div>
<div class="user-description-box col-md-7">
<div class="user-name">
<%= #user.full_name %>
</div>
<div class="user-stats">
<div class="user-stats-debates inline-flex"><b class="spacing-margin-right">
<%= #user.groups.length %></b><% if #user.groups.length == 0 %>
<p> débat</p><% else %><p> débats</p>
</div>
<% end %>
<div class="user-stats-followers inline-flex"><b class="spacing-margin-right"><%= #user.followers.length %></b> <%if #user.followers.length == 0%>
<p> disciple</p> <% else %><p> disciples</p>
<% end %>
</div>
<div class="form-input inline-flex">
<%= form.text_field :description, placeholder: "Description", class: "form-control" %>
</div>
<div class="form-input save-edit">
<%= form.submit "Sauvegarder", class: "form-control profile-submit-button" %>
</div>
<% end %>
<div class="col-md-2">
</div>
</div>
</div>
</div>
</div>
Any answer would be much appreciated.
So in terms of the way you are using bootstrap you are supposed to input all the items that you want in a row which you did but it all the col-md- should add up to a total of 12 for it to be a complete row you have col-md-7 which you should add with an col-xs to make it full also in terms on how to make it like this I think this should suffice
here is some layout that looks like what you are trying to do
<div class="container">
<div class="row">
<div class="col-md-4">
IMAGE
</div>
<div class="col-md-8">
<div class="header">
<h1 class="page-header text-center">MY NAME</h1>
</div>
<div class="row">
<div class="col-md-6">
<h3 class="text-center">insert contents here</h3>
<center>
<div class="center">
<button class="btn btn-primary">BTN</button>
</div>
</center>
</div>
<div class="col-md-6">
<h3 class="text-center">insert contents here</h3>
<center>
<div class="center">
<button class="btn btn-primary">BTN</button>
</div>
</center>
</div>
</div>
</div>
</div>
</div>
It looks like you are inputting user information stay away from #user tags and information like .file and other such things use tags and set them with an ID and then be sure use javascript to manipulate them

How to apply boostrap style to .aspx view?

a need apply boostrap style in mi DropDownList only in the view, not my model
<% using (Html.BeginForm(FormMethod.Post))
{ %>
<%: Html.ValidationSummary(true) %>
<div class="form-group">
<div class="row">
<div class="col-md-6 text-right">
Pais:
</div>
<div class="col-sm-6">
<%: Html.DropDownList("CodPais", String.Empty) %>
<p class="label label-danger"><%: Html.ValidationMessageFor(model => model.CodPais) %> </p>
</div>
</div>
</div>
<% } %>
someone has documentation on how to apply bootstrap in visual .aspx
i try:

bootstrap form-group rows not working

I'm not sure what I'm doing wrong here. The form-group class should act like a row in the form-horizontal form, correct? Here's the code. It's an add/drop page for fantasy football.
<h2>Add/Drop Player</h2>
<div class="container">
<%= form_tag(slot_do_add_drop_path(#slot), method: 'post', :html => {:class => 'form-horizontal', :role => 'form'}) do %>
<div class="form-group">
<div class="col-sm-2">Player to Drop</div>
</div>
<div class="form-group">
<div class="col-sm-2"><%= #slot.player.display_name %> - <%= #slot.player.position %></div>
</div>
<div class="form-group">
<div class="col-sm-2">Add Player</div>
</div>
<%= render partial: "free_agent_select", locals: {free_agents: #free_agents_qbs, p_id: 'qb_id', prompt: 'Select QB'}%>
<%= render partial: "free_agent_select", locals: {free_agents: #free_agents_wrs, p_id: 'wr_id', prompt: 'Select WR'}%>
<%= render partial: "free_agent_select", locals: {free_agents: #free_agents_rbs, p_id: 'rb_id', prompt: 'Select RB'}%>
<%= render partial: "free_agent_select", locals: {free_agents: #free_agents_tes, p_id: 'te_id', prompt: 'Select TE'}%>
<%= render partial: "free_agent_select", locals: {free_agents: #free_agents_ks, p_id: 'k_id', prompt: 'Select K'}%>
<%= render partial: "free_agent_select", locals: {free_agents: #free_agents_defs, p_id: 'def_id', prompt: 'Select DEF'}%>
<div class="form-group">
<div class="col-sm-2">
<%= submit_tag 'Submit', name: 'add_drop_player', class: 'form-control'%>
</div>
</div>
<% end %>
</div>
The partial free_agent_select
<div class="form-group">
<div class="col-md-2">
<%= collection_select :player, p_id, free_agents, :id, :display_name, {:prompt => prompt}, {:class => 'form-control'} %>
</div>
</div>
You should use a row class for each new "row" to solve overlap problem like this.
<div class="form-group row">
<div class="col-sm-2">Player to Drop</div>
</div>
It should be noted that form-group won't wrap floated elements. In this instance all elements with .col-xx-xx add a float to it's container. Adding the class name of .row simply adds the clear-fix of having a ::before and ::after element added to the element (in this case a div) and then applying the css property of clear:both to those elements. You do not need to have the class name of .row added to the parent element you can simply add .clearfix as a class. As it is purely semantics the decision is up to you.
<div class="form-group">
<label for="firstName">First Name</label>
<input id="firstName" name="firstName" class="form-control" />
</div>
<div class="form-group clearfix">
<div class="col-sm-3">CLEAR INFORMATION</div>
<div class="col-sm-3"><button class="btn btn-default" type="submit">SUBMIT</button></div>
</div>
I had a similar problem and fixed it using Zanderi's suggestion (clearfix).
However, when I changed to bootstrap 4.0 I found out that it all worked fine by default, so my suggestion: leave default code, like:
<form class="dropdown-menu dropdown-menu-right" style="padding: 15px">
<div class="form-group">
<label>Nombre</label>
<input class="form-control" id="name" placeholder="Nombre">
</div>
<div class="form-group">
<label>Imagen</label>
<input class="form-control" type="file" id="image">
</div>
<button type="submit" class="btn btn-default pull-right">Guardar</button>
</form>
and use bootstrap 4.0.

Resources