0

Example taken from Firebase Guide

I have a form and I want to pass the form input values into here. How do I populate "San Francisco" dynamically based on what the form input values are?

I have tried creating variables and populate the fields with the variables as such but I received an error message that says

error.ts:166 Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field eventName in document events/RNiEJ9nUxVO1IGFr0TL5)

enter image description here

Reference link: https://firebase.google.com/docs/firestore/query-data/get-data#web

Donavan Er
  • 27
  • 7
  • just to have this fully clear, you want to post the data loaded on the form to Firestore or do you want the form to be loaded with firestore data? – Soni Sol Aug 05 '20 at 18:41
  • Does this answer your question? [Convert form data to JavaScript object with jQuery](https://stackoverflow.com/questions/1184624/convert-form-data-to-javascript-object-with-jquery) – Eric Aug 05 '20 at 20:58
  • @JoséSoní I want to upload the data loaded on the form to Firestore – Donavan Er Aug 06 '20 at 01:37
  • I edited the answer to leave the code as a code snippet, in Stack Overflow it is better to share code as a snippet than as an image – Soni Sol Aug 07 '20 at 21:18
  • Thank you, @JoséSoní – Donavan Er Aug 13 '20 at 12:40

1 Answers1

1

The variable value was undefined. This should solve it.

db.collection("events").add({
    eventName: document.getElementById('eName').value.toString(),
    organiserName: document.getElementById('oName').value.toString(),
    eventDescription: document.getElementById('oDesc').value.toString(),
    eDateTime: document.getElementById('eDateTime').value.toString(),
    eType: document.getElementById('eType').value.toString(),
})
Soni Sol
  • 2,367
  • 3
  • 12
  • 23
Donavan Er
  • 27
  • 7