horus

horus

Phoenix forms with custom grid

Hi guys, im working on a form:


it is written in html, im using liveview and the form is rendered inside a modal live_component.
Actually I’m looking to rewrite it with pure phoenix html tags and form_for but I don’t know if this approach will allow me to handle the grid to put the items as I want I tried different ways but they doesn’t work.
It is possible to do this? or for handling rows and column better to use the html form?
this is my html code:

<div id="<%= @id %>">
  <form phx-submit="submit_form" phx-target="#<%= @id %>">
    <div class="row">
      <div class="form-group col-md-4">
        <label for="inputName">Name</label>
        <input name="name" type="text" class="form-control" id="name">
      </div>
      <div class="form-group col-md-2">
        <label for="inputState">Timezone</label>
        <select name="timezone" id="inputState" class="form-control">
          <option selected>Select timezone</option>
          <option>UTC</option>
          <option>Naive</option>
        </select>
      </div>
      <div class="form-group col-md-2">
        <label for="inputState">Laguage</label>
        <select name="language" id="inputState" class="form-control">
          <option selected>Select Language</option>
          <option>English</option>
          <option>Spanish</option>
          <option>French</option>
          <option>German</option>
          <option>Arabic</option>
        </select>
      </div>
      <div class="form-group col-md-2">
        <label for="inputState">1st Category</label>
        <select name="category_1" id="inputState" class="form-control">
          <option selected>Select One</option>
          <option>Arts</option>
          <option>Comedy</option>
          <option>Education</option>
          <option>Fiction</option>
          <option>Health</option>
          <option>HIstory</option>
        </select>
      </div>
      <div class="form-group col-md-2">
        <br>
        <br>
        <select name="subcategory_1" id="inputState" class="form-control">
          <option selected>Select One</option>
          <option>Books</option>
          <option>Design</option>
          <option>Fashion</option>
          <option>Food</option>
          <option>Visual Arts</option>
        </select>
      </div>
    </div>

    <div class="row">
      <div class="form-group col-md-4">
        <label for="inputEmail">Email</label>
        <input name="email" type="email" class="form-control" id="email" placeholder="email@example.com"></input>
      </div>
      <div class="form-group col-md-4">
        <label for="inputCopyrights">Copyrights</label>
        <input name="copyrights" type="text" class="form-control" id="copyright" ></input>
      </div>
      <div class="form-group col-md-2">
        <label for="inputState">2nd Category</label>
        <select name="category_2" id="inputState" class="form-control">
          <option selected>Select One</option>
          <option>Books</option>
          <option>Design</option>
          <option>Fashion</option>
          <option>Food</option>
          <option>Visual Arts</option>
        </select>
      </div>
      <div class="form-group col-md-2">
        <br>
        <br>
        <select name="subcategory_2" id="inputState" class="form-control">
          <option selected>Select One</option>
          <option>Comedy Interviews</option>
          <option>Improve</option>
          <option>Stand Up</option>
        </select>
      </div>
    </div>

    <div class="row">
      <div class="form-group col-md-4">
        <label for="inputAddress">Description</label>
        <textarea name="description" class="form-control" id="description"></textarea>
      </div>
      <div class="form-group col-md-4">
       <label for="inputName">Keywords</label>
       <input name="keywords" type="text" class="form-control" id="name">
     </div>
      <div class="form-group col-md-2">
       <label for="inputState">3rd Category</label>
       <select name="category_3" id="inputState" class="form-control">
         <option selected>Select One</option>
         <option>Books</option>
         <option>Design</option>
         <option>Fashion</option>
         <option>Food</option>
         <option>Visual Arts</option>
       </select>
     </div>
      <div class="form-group col-md-2">
         <br>
         <br>
         <select name="subcategory_3" id="inputState" class="form-control">
           <option selected>Select One</option>
           <option>Comedy Fiction</option>
           <option>Drama</option>
           <option>Science Fiction</option>
         </select>
       </div>
    </div>

    <div class="row">
      <div class="form-group col-md-4">
        <div class="form-check">
            <input name="is_private" class="form-check-input" type="checkbox" id="gridCheck">
            <label class="form-check-label" for="gridCheck">
              Is private?
            </label>
        </div>
        <div class="form-check">
          <input name="is_explicit" class="form-check-input" type="checkbox" id="gridCheck">
          <label class="form-check-label" for="gridCheck">
            Is explicit?
          </label>
        </div>
      </div>
      <div class="form-group col-md-4">
        <div class="">
          <label for="customRadioInline1">Show Type</label>
        </div>
        <div class="custom-control custom-radio custom-control-inline">
          <input name="episodic" type="radio" id="customRadioInline1" name="customRadioInline1" class="custom-control-input">
          <label class="custom-control-label" for="customRadioInline1">Episodic</label>
        </div>
        <div class="custom-control custom-radio custom-control-inline">
          <input name="serial" type="radio" id="customRadioInline2" name="customRadioInline1" class="custom-control-input">
          <label class="custom-control-label" for="customRadioInline2">Serial</label>
        </div>
      </div>
      <div class="form-group col-md-4">
        <div class="custom-file">
         <input name="image_file" type="file" class="custom-file-input" id="customFile">
         <label class="custom-file-label" for="customFile">Choose Image</label>
        </div>
      </div>
    </div>

    <button type="submit" class="btn btn-primary">Submit</button>

  </form>
</div>

thanks in advice!

Marked As Solved

chouzar

chouzar

Too bad :frowning: try to see if maybe form_for is creating something that interferes with the original styling; I hope is an easy fix :slightly_smiling_face:.

Also Liked

LTheGreats

LTheGreats

Within the <%= form_for ... %> tag, you can put a <div class="row"> and it would put it in a row as you would expect it. You did say that you tried different ways and that it didn’t seem to work, so could you elaborate on what you tried and what didn’t work?

chouzar

chouzar

Unrelated and I’m unsure of the internal mechanics of form_for and liveview but documentation advises about form limitations.

At this point I would use the inspect tools of the browser to see how styles are being applied. There may be something interfering with the grid structure :thinking: have you tried using css columns or css grid for structuring your form?

Yes you can achieve the same effect; form_for is super useful if you already have your data structured in such a way that can be read by it :slight_smile: like an Ecto.Changeset.

I personally prefer plain html tags but the functions at Phoenix.HTML.Form bring some niceties to the table; It looks like your form could benefit by using them.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement