Index of every page on this site: llms.txt
All skills
allxsmith avatar

/bestax-form

@9cf369a
by Alex Smithallxsmith/bestax15 stars
2
Run it yourself

Build forms with @allxsmith/bestax-bulma — Field/Control/Label/Help composition, inputs, selects, checkboxes, radios, switches, and advanced controls (Autocomplete, Combobox, TreeSelect, Cascader, Slider, Numberinput, PinInput, Rate, Taginput, File, date/time, Calendar). There is no form/validation library; this skill shows the components and the validate-it-yourself error pattern. Use when building a form, wiring inputs to state, or showing validation/error state.

Use this Skill: https://skilld.dev/gh/allxsmith/bestax/bestax-form

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencespatterns.md

≈3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Reference: form patterns

A complete multi-field form (controlled + manual validation)

No form library — state is plain React, validation is a function, errors surface through color + message + messageColor.

import { useId, useState } from 'react';
import {
  Input,
  Select,
  TextArea,
  Checkbox,
  Button,
  Field,
} from '@allxsmith/bestax-bulma';

interface Values {
  name: string;
  email: string;
  country: string;
  bio: string;
  agree: boolean;
}

function validate(v: Values) {
  const errors: Partial<Record<keyof Values, string>> = {};
  if (!v.name.trim()) errors.name = 'Name is required.';
  if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(v.email))
    errors.email = 'Enter a valid email.';
  if (!v.country) errors.country = 'Pick a country.';
  if (!v.agree) errors.agree = 'You must accept the terms.';
  return errors;
}

export function ProfileForm() {
  const [values, setValues] = useState<Values>({
    name: '',
    email: '',
    country: '',
    bio: '',
    agree: false,
  });
  const [submitted, setSubmitted] = useState(false);
  const agreeErrorId = useId();

  const errors = validate(values);
  const show = (k: keyof Values) => (submitted ? errors[k] : undefined);
  const set = (k: keyof Values, val: Values[keyof Values]) =>
    setValues(prev => ({ ...prev, [k]: val }));

  return (
    <form
      onSubmit={e => {
        e.preventDefault();
        setSubmitted(true);
        if (Object.keys(errors).length === 0) {
          // submit values…
        }
      }}
    >
      <Input
        label="Name"
        autoComplete="name"
        value={values.name}
        onChange={e => set('name', e.target.value)}
        color={show('name') ? 'danger' : undefined}
        aria-invalid={!!show('name')}
        message={show('name')}
        messageColor="danger"
      />

      <Input
        label="Email"
        type="email"
        autoComplete="email"
        value={values.email}
        onChange={e => set('email', e.target.value)}
        color={show('email') ? 'danger' : undefined}
        aria-invalid={!!show('email')}
        message={show('email')}
        messageColor="danger"
        iconLeftName="envelope"
      />

      <Select
        label="Country"
        autoComplete="country"
        value={values.country}
        onChange={e => set('country', e.target.value)}
        color={show('country') ? 'danger' : undefined}
        aria-invalid={!!show('country')}
        message={show('country')}
        messageColor="danger"
      >
        <option value="">Select…</option>
        <option value="us">United States</option>
        <option value="ca">Canada</option>
      </Select>

      <TextArea
        label="Bio"
        value={values.bio}
        onChange={e => set('bio', e.target.value)}
        rows={3}
      />

      <Field>
        <Checkbox
          checked={values.agree}
          onChange={e => set('agree', e.target.checked)}
          aria-invalid={!!show('agree')}
          aria-describedby={show('agree') ? agreeErrorId : undefined}
        >
          {' '}
          I accept the terms
        </Checkbox>
        {show('agree') && (
          <p id={agreeErrorId} className="help is-danger">
            {show('agree')}
          </p>
        )}
      </Field>

      <Button color="primary" type="submit" mt="4">
        Save
      </Button>
    </form>
  );
}

Notes:

  • Validation runs every render as a pure function; submitted gates when errors are shown so the form isn't red before the user interacts. You could gate per-field on blur instead.
  • For the checkbox the convenience message prop isn't used; the help text is rendered manually inside the Field — a good illustration of dropping to composition when needed. It gets an id the checkbox's aria-describedby points at, which message does for you on the inputs.

Grouped controls and addons

An addon row with its label on an outer Field is the example in SKILL.md, under "Layout via Field".

// Two controls on one row, each with its own label.
<Field grouped>
  <Control>
    <label className="label" htmlFor="first-name">
      First name
    </label>
    <InputBase id="first-name" autoComplete="given-name" />
  </Control>
  <Control>
    <label className="label" htmlFor="last-name">
      Last name
    </label>
    <InputBase id="last-name" autoComplete="family-name" />
  </Control>
</Field>

// A search box whose button says what it does.
<Field hasAddons>
  <Control isExpanded>
    <InputBase type="search" aria-label="Search" />
  </Control>
  <Control>
    <Button color="primary">Search</Button>
  </Control>
</Field>

A grouped or hasAddons Field names none of the controls it holds, so give each input in the row a label on screen (a placeholder isn't one: it goes once the user types).

  • Addon row: a hasAddons Field lays out everything it holds in its row, a label included, so the label goes on an outer Field. Wire it with labelProps={{ htmlFor }} and a matching id on the input: the inner Field starts its own scope, so without them the label shows and names nothing. The label needs an id too, labelProps={{ htmlFor, id }}, when the row holds an Autocomplete, Combobox or Taginput (whose list points aria-labelledby at it; a Combobox's htmlFor names its field's id) or a range Slider (whose thumbs do). A second control beside the labeled input, such as a country-code Select, takes an aria-label.
  • Grouped row: each Control holds a <label className="label"> whose htmlFor points at its input. A convenience input's own label renders nothing inside a Field (a grouped row, an addon row or an outer labeled Field), so it can't stand in for one. An input and the button that sends it read better as an addon row with an outer label: in a labeled grouped row the button lines up with the labels, not the inputs.
  • Search box: an aria-label alone is enough when its button says what it does.

In a component that renders more than once, make each id with useId rather than a fixed string.

A show-password button is not an addon recipe: use PasswordInput, whose button sits inside the field. Never put it in iconRight, since Bulma gives control icons pointer-events: none and a click on one lands on the input.

Recipes built on addons, each written out in full in the docs:

  • Copy field (docs): a read-only input and a CopyButton value={text} in the second Control. It writes, falls back where the Clipboard API is missing, reads "Copied" and announces the result itself, from a region it portals out of the Control. For a failure, keep labels.failedStatus short and put the instruction ("the link is selected, so copy it from the field") in a help line under the field that is the input's aria-describedby, not another live region. Count failures in onCopyError, and focus and select the input in an effect on that count, so focus arrives once the description is in the page and a screen reader reads it with the field. onCopiedChange clears the count.
  • Split button (docs): a Button and a Dropdown in Field hasAddons, one Control each. Buttons hasAddons does not join the Dropdown's trigger. Keep the default color, since the trigger takes no color.

Horizontal field with explicit label/body

Field.Label is the label column, not a <label>, so text placed straight in it names nothing: put a <label className="label"> inside it with htmlFor pointing at the input's id.

<Field horizontal>
  <Field.Label size="normal">
    <label className="label" htmlFor="horizontal-email">
      Email
    </label>
  </Field.Label>
  <Field.Body>
    <Control iconLeftName="envelope" hasIconsLeft>
      <InputBase
        id="horizontal-email"
        type="email"
        autoComplete="email"
        placeholder="you@example.com"
      />
    </Control>
  </Field.Body>
</Field>

Advanced inputs

These are controlled the same way — own the value, pass value/onChange.

// Autocomplete — onInput fires on typing, onSelect when a suggestion is chosen.
const [city, setCity] = useState('');
<Autocomplete
  value={city}
  onInput={setCity}
  onSelect={item =>
    setCity(typeof item === 'string' ? item : (item?.value ?? ''))
  }
  data={['Austin', 'Boston', 'Chicago']}
  openOnFocus
/>;

// Combobox: a value from a list. Given data, it filters by label, keeps the
// value and shows its label in the field.
const [country, setCountry] = useState<string | null>(null);
<Combobox
  label="Country"
  data={['Canada', 'France', 'Japan']}
  value={country}
  onChange={setCountry}
  empty="No countries match"
/>;

// Several values, shown as tags under the field; groups come from `group`.
const [labels, setLabels] = useState<string[]>([]);
<Combobox
  label="Labels"
  multiple
  data={[
    { value: 'bug', label: 'Bug', group: 'Type' },
    { value: 'docs', label: 'Docs', group: 'Area' },
  ]}
  value={labels}
  onChange={setLabels}
/>;

// From parts, when data doesn't fit (a server search, a "Create" item): you
// filter, keep the value and set the text, and a pick calls onSelect.
const countries = ['Canada', 'France', 'Japan'];
const [choice, setChoice] = useState<string | null>(null);
const [query, setQuery] = useState('');
const term = query === choice ? '' : query.trim().toLowerCase();
const matches = countries.filter(c => c.toLowerCase().includes(term));
<Combobox
  label="Country"
  onSelect={picked => {
    setChoice(picked);
    setQuery(picked);
  }}
>
  <Combobox.Input value={query} onChange={e => setQuery(e.target.value)} />
  <Combobox.Menu>
    {matches.length > 0 ? (
      <Combobox.List>
        {matches.map(c => (
          <Combobox.Item key={c} value={c} checked={c === choice}>
            {c}
          </Combobox.Item>
        ))}
      </Combobox.List>
    ) : (
      <Combobox.Empty>No countries match</Combobox.Empty>
    )}
  </Combobox.Menu>
</Combobox>;

// Slider (single and dual thumb)
const [volume, setVolume] = useState(50);
<Slider
  label="Volume"
  value={volume}
  onChange={setVolume}
  min={0}
  max={100}
  tooltip="auto"
/>;

const [range, setRange] = useState<[number, number]>([20, 80]);
// The label names both thumbs: "Price range Minimum value" / "... Maximum value".
<Slider
  range
  label="Price range"
  value={range}
  onChange={setRange}
  min={0}
  max={100}
/>;

// Numberinput
const [qty, setQty] = useState(1);
<Numberinput
  label="Quantity"
  value={qty}
  onChange={setQty}
  min={1}
  max={10}
  step={1}
/>;

// PinInput: a one-time code or PIN, a box per character, all in one input.
// onComplete fires once each time a change fills the last box.
const [code, setCode] = useState('');
const verify = (otp: string) => {
  // Send it to your server, then show the result with color and message.
};
<PinInput
  label="Enter the 6-digit code"
  name="otp"
  value={code}
  onChange={setCode}
  onComplete={verify}
/>;

// Rate
const [stars, setStars] = useState(3);
<Rate value={stars} onChange={setStars} max={5} />;

// Taginput — tags can be strings or { value, label } objects; onChange yields TaginputTag[].
const [tags, setTags] = useState<string[]>(['react']);
<Taginput
  value={tags}
  onChange={next =>
    setTags(next.map(t => (typeof t === 'string' ? t : t.value)))
  }
  data={['react', 'bulma', 'ts']}
/>;

Each renders inside Bulma's field/control structure already, so wrap them in a Field only when you need a label or grouped layout. Reflect validation on them with the same color / message / messageColor approach used for text inputs.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts18d3 checks · Risk SAFE
  • Gen Agent Trust Hub18d

    The skill provides documentation and code patterns for building web forms using the @allxsmith/bestax-bulma component library. No security issues were detected.

  • Socket18d

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at 9cf369a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 days ago

README badge

README badge for allxsmith/bestax/bestax-form