Skip to content

Attribute helpers for JSON data attributes #15

@kissgyorgy

Description

@kissgyorgy

There are cases where frameworks configure behavior by setting a JSON object in a HTML element data attribute, e.g. Alpine.JS, Preline UI.
A helper is useful in these cases.

Real example with Preline UI:

  config = {
      "url": reverse("profile-picture-upload"),
      "acceptedFiles": "image/*",
      "maxFiles": 1,
      "singleton": True,
      "paramName": "profile_picture",
      "previewsContainer": "#profile-picture-preview",
      "headers": {
          "X-CSRFToken": get_token(request),
      },
  }

  with html.Div(
      class_="inline-block dz-max-files-reached",
      data_hs_file_upload=safe(json.dumps(config)),
  ):
      ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions