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

162
Visualizações
An error occurs while adding data to the database

In the application, the user can create his own bank. He enters the appropriate data into the fields and when you click on the "Add" button, the fields should be written to the database. But now when I click, I get an error - Uncaught FirebaseError: Function addDoc() called with invalid data. Unsupported field value: a custom HTMLInputElement object (found in field bankName in document bank-items/AMgVThS6caX9BJuCeezJ) How can it be solved?

const addBankButton = document.getElementById("add-bank");

const addBankFunc = () => {
  addBankButton.addEventListener("click", (event) => {
    event.preventDefault();
    const bankName = document.getElementById("bank-name");
    const interestRate = document.getElementById("interest-rate");
    const maximumLoan = document.getElementById("maximum-loan");
    const minimumDownPayment = document.getElementById("minimum-down-payment");
    const loanTerm = document.getElementById("loan-term");

    db.collection("bank-items").add({
      bankName: bankName,
      interestRate: interestRate,
      maximumLoan: maximumLoan,
      minimumDownPayment: minimumDownPayment,
      loanTerm: loanTerm,
    });
  });
};

addBankFunc();
   <form>
                        <input id="bank-name" type="text" placeholder="Bank name" />
                        <input id="interest-rate" type="text" placeholder="Interest rate" />
                        <input id="maximum-loan" type="text" placeholder="Maximum loan" />
                        <input id="minimum-down-payment" type="text" placeholder="Minimum down payment" />
                        <input id="loan-term" type="text" placeholder="Loan term" />
                        <button id="add-bank">Add bank</button>
                    </form>

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

0

You should pass value of the input fields to Firestore (that would be a string/number) instead of the HTML element itself. Try getElementById return an Element object that is not a valid Firestore data type. Try refactoring the code as shown below:

const bankName = document.getElementById("bank-name").value;
// add .value for every element
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