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

488
Visualizações
Adding options dynamically , selected and not selected

In this code I want to inject options. How can I pass that using the inject function? Also pass in case some option is already selected.

dynamic_form.inject([{
  p_name: ['One','two'],
  quantity: '123',
  remarks: 'testing remark'
}, {
  p_name: ['One','two'],
  quantity: '123',
  remarks: 'testing remark'
}]);

This part of JSON is a bit confusing

$.each(formValue, function(index, value) {
  if ($.isArray(value)) {
    mainForm = clone.find("#" + index);
    if (typeof mainForm.get(0).getSource === "function") {
      $.each(value, $.proxy(fillData, mainForm.get(0).getSource()));
    }
  } else {
    var formElements = changeArray[formIndex].find("[origname='" + index + "']");
    if (formElements) {
      if (formElements.get(0).tagName.toLowerCase() == "input") {
        /* Fill in radio input */
        if (formElements.attr("type") == "radio") {
          formElements.filter("[value='" + value + "']").attr("checked", "checked");
        } else if (formElements.attr("type") == "checkbox") { /* Fill in checkbox input */
          formElements.attr("checked", "checked");
        } else {
          formElements.attr("value", value);
        }
      } else if (formElements.get(0).tagName.toLowerCase() == "textarea") {
        /* Fill in textarea */
        formElements.text(value);
      } else if (formElements.get(0).tagName.toLowerCase() == "select") {
        /* Fill in select */
        $(formElements.get(0)).find("option").each(function() {
          if ($(this).text() == value || $(this).attr("value") == value) {
            $(this).attr("selected", "selected");
          }
        });
      }
    }
  }
});
about 4 years ago · Juan Pablo Isaza
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