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

207
Visualizações
Create dynamic form with parameters

On a grid I have to create a (popup) form dynamically, based on a JSON that has the data for what type of input goes on the form. For the select type, the options are different for every form, and all the options are in another JSON that is called based on the name on the previous JSON.

example. I click on button "create report" for row number 1 on grid. popup open up with form to get the filter of the report. the button call the 1st JSON that is like this:

[
    {
        "name": "Report Users residence",
        "input": [{
            "type": "select",
            "name": "city",
        },
        {
            "type": "select",
            "name": "address",
        }]
    }   
]

In this case the cities are in another JSON called "city.json".

[
    {
        "code": "000000",
        "description": "City1"
    },
    {
        "code": "000001",
        "description": "City2",
    }
]

I was able to create the form, but i don't know how to get the option of the 2nd JSON on the select "city".Can someone give me an example on how to do it?

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

0

First, city data have to converted into object. After that using jQuery $.each method, you can loop over city object to create option for select and append into the select.

This is an example of the idea :

<select name="city"></select>

<script>

    var city = [{"code":"000000","description":"City1"},{"code":"000001","description":"City2",}];
    var citySelect = $(document).find('select[name="city"]');

    $(city).each(function(key,item){

        var cityOption = new Option(item.description,item.code);
        citySelect.append(cityOption);
    });
    
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="city"></select>

<script>

    var city = [{"code":"000000","description":"City1"},{"code":"000001","description":"City2",}];
    var citySelect = $(document).find('select[name="city"]');

    $(city).each(function(key,item){

        var cityOption = new Option(item.description,item.code);
        citySelect.append(cityOption);
    });
    
</script>

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