search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Update a Kanban card

Asked by Anonymous
10 months ago.

How do you update a single card after editing it.
Are we being stupid as we cannot find any guidance on how that is done.

Answer posted by Dan Letecky [DayPilot]
10 months ago.

Example:

onCardClick: async args => {
    const form = [
        {id: "name", name: "Name", type: "text"},
        {id: "text", name: "Description", type: "textarea"}
    ];
    const modal = await DayPilot.Modal.form(form, args.card.data);
    if (modal.canceled) {
        return;
    }
    args.card.data.name = modal.result.name;
    args.card.data.text = modal.result.text;
    kanban.cards.update(args.card);
}

You can update the card by calling cards.update(). The argument must be the original Card object (but you can modify the properties of args.card.data as needed).

Comment posted by Anonymous
10 months ago.

When you right click the context menu, the args passed has a source property. Is that the card object?

We tried using that but it does not work.

Comment posted by Dan Letecky [DayPilot]
10 months ago.

Yes. You can try something like this:

contextMenuCard: new DayPilot.Menu({
    items: [
        {
            text: "Edit...", onClick: async (args) =>{
                const card = args.source;
                const form = [
                    {id: "name", name: "Name", type: "text"},
                    {id: "text", name: "Description", type: "textarea"}
                ];
                const modal = await DayPilot.Modal.form(form, card.data);
                if (modal.canceled) {
                    return;
                }
                card.data.name = modal.result.name;
                card.data.text = modal.result.text;
                kanban.cards.update(card);
            }
        },
        {text: "-"},
        {
            text: "Delete", onClick: (args) => {
                kanban.cards.remove(args.source);
            }
        }
    ]
})

If you don’t have the Card object for some reason, you get get it using cards.find(id):

const card = kanban.cards.find(1);
card.data.name = "Task 1";
kanban.cards.update(card);
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.