Tasks: Raw JSON displayed when adding category

Created on 20 May 2019  路  11Comments  路  Source: nextcloud/tasks

Steps to reproduce

  1. Create a task
  2. Start typing to add a category

Expected behaviour

The text next to the plus sign should be just the name of the new category.

Actual behaviour

The text next to the plus sign is something like {"isTag": "true", "label": "example"}.

screenshot

Server configuration

Operating system: Fedora 30
Web server: nginx
Database: MariaDB
PHP version: 7.2
Nextcloud version: 16.0.1
Tasks version: 0.10.1
Updated from an older Nextcloud or fresh install: Older install
Signing status: can't do at the moment, away from home

Client configuration

Browser: Chrome and Firefox

bug upstream

Most helpful comment

I think you cannot use an array of string with @tag.
https://vue-multiselect.js.org/#sub-tagging
This needs to be objects.

That's a limitation / bug introduced by the vue-components. If I use the upstream vue-multiselect it works just fine with an array of strings:
noerror

Corresponding component:

<template>
    <div>
        <Multiselect
            v-model="categories"
            :multiple="true"
            :searchable="true"
            :options="categories"
            :placeholder="'Select categories'"
            :taggable="true"
            :tag-placeholder="'Add this as a new category'"
            :close-on-select="false"
            class="multiselect-vue"
            @input="updateCategories"
            @tag="updateCategory"
        />
    </div>
</template>

<script>
import Multiselect from 'vue-multiselect'

export default {
    components: {
        Multiselect,
    },
    data: function() {
        return {
            categories: ['a', 'b', 'c'],
        }
    },
    methods: {
        /**
         * Sets the categories of a task
         *
         * @param {Array} categories The new categories
         */
        updateCategories: function(categories) {
            console.debug('Set categories to ' + categories)
        },

        /**
         * Adds a category to the list of categories
         *
         * @param {String} category The name of the category to add
         */
        updateCategory: function(category) {
            console.debug('Add categoriy ' + category)
        },
    }
}
</script>

I will create an issue in the vue-components.

All 11 comments

@skjnldsv Do you have an idea what might be wrong here?

task.categories is a plain array. It doesn鈥檛 have a key and label. What do I specify then? Or doesn鈥檛 it work with an array?

@raimund-schluessler well, this is an array of objects, right?
You therefore needs to use label="label" and track-by="label"
But I would still suggest having a proper id here. Because you need to make sure there is no duplicate :thinking:

At the moment it is an array of strings coming from the VTODO https://github.com/nextcloud/tasks/blob/master/src/models/task.js#L405

I can of course create an array of objects from it.

@raimund-schluessler Well, if there is a json displayed, it means this is no longer a string but an object. So there must be an issue somewhere.
If you using only an array of string you don't need label/trackBy :)

To be honest, I think this is a bug in the vue-components.
This component

<template>
    <div>
        <Multiselect
            v-model="categories"
            :multiple="true"
            :searchable="true"
            :options="categories"
            :placeholder="'Select categories'"
            :taggable="true"
            :tag-placeholder="'Add this as a new category'"
            :close-on-select="false"
            class="multiselect-vue"
            @input="updateCategories"
            @tag="updateCategory"
        />
    </div>
</template>

<script>
import { Multiselect } from 'nextcloud-vue'

export default {
    components: {
        Multiselect,
    },
    data: function() {
        return {
            categories: ['a', 'b', 'c'],
        }
    },
    methods: {
        /**
         * Sets the categories of a task
         *
         * @param {Array} categories The new categories
         */
        updateCategories: function(categories) {
            console.debug('Set categories to ' + categories)
        },

        /**
         * Adds a category to the list of categories
         *
         * @param {String} category The name of the category to add
         */
        updateCategory: function(category) {
            console.debug('Add categoriy ' + category)
        },
    }
}
</script>

renders a multiselect like this
Screenshot_2019-05-21 Aufgaben - Nextcloud
which shows the same error (Raw JSON) when typing
error

Also, if I am not wrong, this used to work correctly when I first implemented categories. I assume an update of the vue-components broke it. Shall I open an issue in the vue-components repo?

AH, I get it I think. You're creating a new tag.
I think you cannot use an array of string with @tag.
https://vue-multiselect.js.org/#sub-tagging
This needs to be objects.

I think you cannot use an array of string with @tag.
https://vue-multiselect.js.org/#sub-tagging
This needs to be objects.

That's a limitation / bug introduced by the vue-components. If I use the upstream vue-multiselect it works just fine with an array of strings:
noerror

Corresponding component:

<template>
    <div>
        <Multiselect
            v-model="categories"
            :multiple="true"
            :searchable="true"
            :options="categories"
            :placeholder="'Select categories'"
            :taggable="true"
            :tag-placeholder="'Add this as a new category'"
            :close-on-select="false"
            class="multiselect-vue"
            @input="updateCategories"
            @tag="updateCategory"
        />
    </div>
</template>

<script>
import Multiselect from 'vue-multiselect'

export default {
    components: {
        Multiselect,
    },
    data: function() {
        return {
            categories: ['a', 'b', 'c'],
        }
    },
    methods: {
        /**
         * Sets the categories of a task
         *
         * @param {Array} categories The new categories
         */
        updateCategories: function(categories) {
            console.debug('Set categories to ' + categories)
        },

        /**
         * Adds a category to the list of categories
         *
         * @param {String} category The name of the category to add
         */
        updateCategory: function(category) {
            console.debug('Add categoriy ' + category)
        },
    }
}
</script>

I will create an issue in the vue-components.

Was fixed with https://github.com/nextcloud/nextcloud-vue/pull/538 upstream, will come with the next release of vue-components.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thomas-mc-work picture thomas-mc-work  路  3Comments

schiessle picture schiessle  路  9Comments

gjgd picture gjgd  路  6Comments

enboig picture enboig  路  9Comments

jakobroehrl picture jakobroehrl  路  3Comments