A Val Town voting widget that provides embeddable HTML voting components with SQLite persistence and vote limiting.
import { createVotingWidget, initializeOptions } from "./index.ts";
const config = {
pollId: "my-poll-2024",
maxTotalVotes: 1000,
maxVotesPerUser: 3,
options: [
{ id: "option1", title: "Option 1", description: "First choice" },
{ id: "option2", title: "Option 2", description: "Second choice" },
{ id: "option3", title: "Option 3" }
]
};
// Initialize the poll options in the database
await initializeOptions(config);
// Generate HTML widget
const widgetHTML = createVotingWidget(config);
The component provides these API endpoints:
POST /api/vote
- Submit a voteGET /api/results/:pollId
- Get current results{ "pollId": "my-poll-2024", "optionId": "option1", "voterId": "unique-voter-id", "maxTotalVotes": 1000, "maxVotesPerUser": 3 }
kuadratic_votes_1
id
- Auto-increment primary keypoll_id
- Poll identifieroption_id
- Selected option IDvoter_id
- Unique voter identifiertimestamp
- Vote timestampkuadratic_options_1
id
- Option ID (primary key)poll_id
- Poll identifiertitle
- Option titledescription
- Optional descriptionvote_count
- Current vote countpollId
: Unique identifier for the pollmaxTotalVotes
: Maximum total votes allowed across all usersmaxVotesPerUser
: Maximum votes per individual useroptions
: Array of voting optionsThe component enforces two types of limits:
The widget generates self-contained HTML with embedded CSS and JavaScript. Simply insert the generated HTML into any webpage to enable voting functionality.
The component automatically: