Spring mvc bootstrap

Asked

Viewed 125 times

0

Galera is the following I have a record that I get with the bootstrap select element and I select it and I need to put a button to add this record in a table below that on the same page where the select and a button add, and need to add other records that is loaded in select i select one at a time and clik in the button add and there is to add dynamically in a table below where should have a button remove in the table then after I select the desired records will have a save button to actually save in the bank I need help to do this part

1 answer

0

Your question is answered with a Jquery implementation and an HTML post for Spring MVC to handle your choices, but is not really related to Spring MVC or Bootstrap.

Why, once you’ve loaded your select with the required fields, and an "Add" button next to it, the chosen value will be sent to a form initially empty, which, when submitted, sends the chosen codes to the page responsible for treating them. In addition it is clear to insert visually on the screen for the user as feedback and remove them from select.

<p>Para onde você quer ir?</p>
<select id="meu_select">
  <option value="1">Paris</option>
  <option value="2">Moscou</option>
  <option value="3">Roma</option>
  <option value="4">Viena</option>
</select>
<button onclick="minha_funcao();">Adicionar</button>

<p>Você já escolheu:</p>
<div id="escolhas">
  <!-- Inicialmente vazio! -->
</div>

<form id="meu_form" method="post" action="/pagina_responsavel.php">
  <input type="submit" value="Submeter escolhas">
</form>

<script>
function minha_funcao() {
  if($('#meu_select').val()) {
    // Adiciona no post uma variável que tem nome criado a partir do 
    // valor escolhido (id_...) e o valor escolhido
    $('#meu_form').append('<input type="hidden" name="id_' + 
      $('#meu_select').val() + '" value="' + $('#meu_select').val() + '">');

    // Adiciona na tela o valor escolhido
    $("#escolhas").append("<p>" + $('#meu_select option:selected').text() + "</p>");

    // Remove do select o valor escolhido
    $("#meu_select option[value=\""+$('#meu_select').val()+"\"]").remove();
  }
}

</script>

The easiest way to know what value(s) was (were) chosen(s), is to check whether for each value sent to the select there is a post variable id_value, where value is 1, 2, 3, 4, etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.