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

Update a Kanban card

Asked by Anonymous
3 days 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]
3 days 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
3 days 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]
2 days 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);
New Reply
This reply is
Attachments:
or drop files here
Your name (optional):