• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
cricks_unmixed4u

cricks_unmixed4u

kuadratic

Remix of cricks_unmixed4u/ai-prompted
Public
Like
kuadratic
Home
Code
9
.cursor
1
dist
1
lib
5
public
1
.cursorrules
.vtignore
deno.json
knowledge.md
H
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
lib
/
README.md
Code
/
lib
/
README.md
Search
6/24/2025
README.md

Kuadratic Voting Component

A Val Town voting widget that provides embeddable HTML voting components with SQLite persistence and vote limiting.

Features

  • Multiple Options: Display multiple voteable options in a single poll
  • Persistent Storage: All votes stored in Val Town's SQLite database
  • Vote Limiting: Configurable limits for total votes and votes per user
  • Embeddable: Export HTML components for easy integration
  • Real-time Updates: Vote counts update immediately after voting

Usage

Basic Example

Create val
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);

API Endpoints

The component provides these API endpoints:

  • POST /api/vote - Submit a vote
  • GET /api/results/:pollId - Get current results

Vote Submission

{ "pollId": "my-poll-2024", "optionId": "option1", "voterId": "unique-voter-id", "maxTotalVotes": 1000, "maxVotesPerUser": 3 }

Database Schema

kuadratic_votes_1

  • id - Auto-increment primary key
  • poll_id - Poll identifier
  • option_id - Selected option ID
  • voter_id - Unique voter identifier
  • timestamp - Vote timestamp

kuadratic_options_1

  • id - Option ID (primary key)
  • poll_id - Poll identifier
  • title - Option title
  • description - Optional description
  • vote_count - Current vote count

Configuration

VoteConfig

  • pollId: Unique identifier for the poll
  • maxTotalVotes: Maximum total votes allowed across all users
  • maxVotesPerUser: Maximum votes per individual user
  • options: Array of voting options

Vote Limiting

The component enforces two types of limits:

  1. Global Limit: Total votes across all users
  2. Per-User Limit: Votes per individual (tracked by voter ID)

Integration

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:

  • Loads current vote counts on page load
  • Updates counts in real-time after voting
  • Shows success/error messages
  • Prevents voting when limits are reached
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.