0

I've got a problem using Polymer 2.0 and Firebase. I want to update data to Firebase with firebase-document but when I want to update only the title, it destroy all the previous data and save only the title.

Example of the strucute before update :

myapp:
    categories:
        1:
            logoName: test.png
            title: test

And after :

myapp:
    categories:
        1:
            title: test bis

Do I have to give always the entire record and update only the field I want or can I only give the field I want to update to saveValue. I try to only give the field but it doesn't seem to work

Here is a part of my code :

<dom-module id="categorie-form">
    <template>
        <firebase-document
            id="document"
            app-name="myapp"
            data="{{categorieData}}">
        </firebase-document>

        <iron-form id="categorieIronForm">
            <form id="categorieForm">
                <label for="title">Nom de la catégorie</label>
                <input type="text" name="title" id="title" value="[[name]]">
                <paper-button id="validButton" on-click="_submitCategorie" raised>valider</paper-button>
            </form>
        </iron-form>
    </template>
    <script>
        class CategorieForm extends Polymer.Element {

            static get is () { return "categorie-form" }

            static get properties () {
                return {
                    categorieData: {
                        type: Object
                    }
                }
            }

            _submitCategorie () {
                this.categorieData = {
                    title: form.title.value
                };
                this.$.document.saveValue('/categories', key)
            }
        }
        customElements.define(CategorieForm.is, CategorieForm);
    </script>
</dom-module>

Thank you

jean-max
  • 1,640
  • 1
  • 18
  • 33

1 Answers1

0

try this :

this.$.document.saveValue('/categories/1/title', key)
Oussema Aroua
  • 5,225
  • 1
  • 24
  • 44
  • It create a new row in Firebase with the id `title` in `categories` with the new value – jean-max Jul 25 '17 at 15:04
  • It update the title but instead of setting the value, it create a new object with an id and inside there is the title with the value – jean-max Jul 25 '17 at 15:29
  • well i'm not a good polymer developer, i don't know but try this `/categories/1.title` – Oussema Aroua Jul 25 '17 at 15:30
  • Non, error : `Error: Firebase.child failed: First argument was an invalid path: "/categories/1.title". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"`. Thanks trying to help – jean-max Jul 25 '17 at 15:35