javascript - Easy way to change visual order of input fields dynamically (without changing form HTML)? -


i have form made angular directive template. contains several input fields in order. can not construct form dynamically using ng-repeat approach, because fields have custom behaviour, special validators , such.

 <div id="1"> input field 1</div>  ...  <div id="7"> input field 7</div> 

i have need display these input in different random order under use case. logic , contents of form remains same 1 input used 7th should become 1st. great if can achieve using css class conditionally applied elements (likely, using ng-class option).

what css can possibly use keep same template (sketched above) have visually "div id=7" appear before "div id=1" ?

i prefer avoid dom manipulating , have angular-friendly way.

flexbox can change visual order of elements using order property.

.wrap {    display: flex;    flex-direction: column;  }  .wrap div {    padding: 1em;    border: 1px solid black;    margin-bottom: 1em;  }  #first {    background: #bada55;    font-weight: bold;    order: 7  }  #last {    background: #663399;    color: white;    font-weight: bold;    order: 1  }
<div class="wrap">    <div id="first">i'm first in source order not visually</div>    <div id="last">i'm last in source order visually i'm first</div>  </div>

after that, randomness can added via javascript , order assigned loop (i assume, js fu non-existent).


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -