Live-editing attributes via the API
Last updated
Last updated
Using JavaScript, we can make our own live-editing functionality without the use of Blade’s @liveAttribute()
method and Kanka’s standard modals. For instance, you can make checkboxes that immediately update the entity when ticked and unticked directly on the sheet. Here is a helpful wrapper function that assumes you use the attribute dump provided by the to locate the appropriate API URL.
Using this, you only need to provide a name (slug) and value any time you wish to update an attribute. Here is an example from my Daggerheart character sheet, where I have groups of checkboxes wrapped in a div
with a data-stat
attribute that specifies the slug. My script runs through all such div
s and creates an event listener on each of them:
You can also very easily create new attributes on the entity programmatically:
Only the name
is mandatory; see the API docs for all possible parameters, such as each type_id
.
Likewise, you can easily delete an existing attribute with a simple post to the corresponding URL, should the need arise (though you should have a very good reason to do so):
Watch this space for a way to live-update ability charges through the API.