import { Context } from "koa"; import { FormField } from "../fields/field.js"; import { FormDataValue } from "../form-types.js"; import { Tickable } from "./tickable.js"; export class Radio extends Tickable { type = "radio"; constructor( public field: FormField, public value: string, options: { label?: string } ) { super(field, { default_value: "", ...options }); } makeInputID(): string { return this.field.name + "-" + this.value.replaceAll(/\W/g, "-"); } getValueAttribute(): string { return this.value; } getWrapperClasses( ctx: Context, data: Record, value: string ): string[] { return [ ...super.getWrapperClasses(ctx, data, value), this.value.replaceAll(/\W/g, "-"), ]; } isChecked( _ctx: Context, _data: Record, value: string ): boolean { return this.value === value; } }