Save value of a select and display

2

I'm developing a CRUD from a web system. In the employee's registry I use two select elements to display the options, when registering everything works ok, the information goes to the bank. The problem is when you click edit and bring this information to select, the select the edit screen comes with the initial value of the select; example: in the register I put that I am support, when editing the field select this administrator and not the correct one, support. Someone can help me to bring the correct information of these selects.

Register screen where you enter the options SUPERVISOR AND SUPPORT

Ontheeditscreen,thefieldsappearasadministrator.

Mystaffform

<divclass="row">
<form action="@{funcionarios.salvarFuncionarios}" method="post">
    <div class="col-lg-6">
        <input type="hidden" name="funcionario.id" value="${f?.id}" />
        <div class="form-group">
            <label>Nome completo:</label> <input type="text"
                name="funcionario.nome" class="form-control"
                value="${flash['funcionario.nome'] ? flash['funcionario.nome'] : f?.nome}">
            <span class="alert-danger">#{error 'funcionario.nome' /}</span>
        </div>

        <div class="form-group">
            <label>Email:</label> <input type="text" name="funcionario.email"
                class="form-control"
                value="${flash['funcionario.email'] ? flash['funcionario.email'] : f?.email}">
            <span class="alert-danger">#{error 'funcionario.email' /}</span>
        </div>

        <div class="form-group">
            <label>Função:</label> <select name="funcionario.funcao"
                class="form-control"
                value="${flash['funcionario.funcao'] ? flash['funcionario.funcao'] : f?.funcao}">
                <option>Administrador</option>
                <option>Suporte</option>
                <option>Supervisor</option>
            </select> <span class="alert-danger">#{error 'funcionario.funcao' /}</span>
        </div>

        <div class="form-group">
            <label>Nível de acesso:</label> <select
                name="funcionario.nivelAcesso" class="form-control"
                value="${flash['funcionario.nivelAcesso'] ? flash['funcionario.nivelAcesso'] : f?.nivelAcesso}">
                <option>Administrador</option>
                <option>Suporte</option>
            </select> <span class="alert-danger">#{error 'funcionario.nivelAcesso'
                /}</span>
        </div>
    </div>
    <div class="col-lg-6">
    #{if f}
        <div class="form-group">
            <label>Nome de usuário:</label> <input id="loginUsuario" type="text" placeholder="Mínimo 5 caracteres"
                name="funcionario.login" class="form-control" disabled="disabled"
                value="${flash['funcionario.login'] ? flash['funcionario.login'] : f?.login}">
            <span class="alert-danger">#{error 'funcionario.login' /}</span>
        </div>
        #{/if}
        #{ifnot f}
        <div class="form-group">
            <label>Nome de usuário:</label> <input id="loginUsuario" type="text" placeholder="Mínimo 5 caracteres"
                name="funcionario.login" class="form-control"
                value="${flash['funcionario.login'] ? flash['funcionario.login'] : f?.login}">
            <span class="alert-danger">#{error 'funcionario.login' /}</span>
        </div>

        <div class="form-group">
            <label>Senha:</label> <input type="password" placeholder="Mínimo 6 caracteres"
                name="funcionario.senha" class="form-control"
                value="${flash['funcionario.senha'] ? flash['funcionario.senha'] : f?.senha}">
            <span class="alert-danger">#{error 'funcionario.senha' /}</span>
        </div>
        <div class="form-group">
            <label>Confirmar senha:</label> <input type="password" name="senha"
                class="form-control"> <span class="alert-danger">#{error
                'senha' /}</span>
        </div>
        #{/ifnot}
    </div>
    <div class="col-lg-12">
        <button type="submit" class="btn btn-success">Salvar</button>
        <button type="reset" class="btn btn-danger"
            onclick="window.location.href='/funcionarios/listagemFuncionarios';">
            Cancelar</button>
    </div>
</form>

    
asked by anonymous 20.08.2017 / 20:35

1 answer

1

The problem is that you are only listing the select data, not defines what will be the selected item of <option> using selected , example:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw">VW</option>
  <option value="audi" selected>Audi</option>
</select>

1- I suggest creating an array with [Administrador,Suporte,Supervisor]

foreach by adding each item to a <option> , if the current item is equal to the item flash['funcionario.funcao'] (previously selected value)

Sorry to be unable to help with the syntax, I hope I have helped.

    
20.08.2017 / 20:53