Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
User defined positioning on a grid of html form fields

I have a form with some input elements that I want to arrange on a grid according to users' preferences. Looking around I have come across CSS grids.

I am thinking about creating a CSS grid with r rows and c columns, and then using javascript to assign input elements to the grid's cells according to a user defined layout (for example, an object having the id of the input elements as keys and the (column-span) pairs as values).

I don't know if this is the best (or even a viable) solution, and it sounds like a lot of boilerplate code to change the CSS properties of the input elements. So my questions are: is this the right approach to this problem? Are there other (better, easier) approaches, not necessarily based on CSS grids?

I am using plain javascript and Vue.js, if it matters (sorry for my imprecise wording, I am a hobbyist, self-taught developer).

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use grid-template-areas to assign elements to a position in the grid irrespective of their order in the DOM.

form {
  display: grid;
  gap: 0.5rem;
  grid-template-areas: "w x" "y z";
}

#a { grid-area: z; }
#b { grid-area: w; }
#c { grid-area: y; }
#d { grid-area: x; }
<form>
  <input id="a" type="text" placeholder="A">
  <input id="b" type="text" placeholder="B">
  <input id="c" type="text" placeholder="C">
  <input id="d" type="text" placeholder="D">
</form>

about 4 years ago · Juan Pablo Isaza Relatório

0

you can set an attribute to the input or any html tag.

If the ordering based on user-preferences, then I assume you will have a json object that tells the position of the fields in the form, so you can set an attribute to the html tag

<span data-column="0" data-row="0" />
<input type='text' data-column="1" data-row="0" />
or 
<input type='text' data-order="1:0" />
<input type='text' data-order="0:0" />

then when generating the form with a loop statement, you can then getAttribute/setAttribute with document.getElementById().setAttribute('attrName','attrValue')

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda