← All 41 libraries

CandyForms

🍬 CandyForms

Foundation lib for form and input primitives

foundation forms inputs leaf-package

CandyForms code coverage

Foundation lib for form and input primitives — the raw component implementations that sugar-bits and sugar-prompt re-export. Extracted out of those two leaf libs so the form/prompt engine can ship as a single standalone dependency.

Install

composer require sugarcraft/candy-forms

Quickstart

use SugarCraft\Forms\Field\Input;
use SugarCraft\Forms\Form;
use SugarCraft\Forms\Validator\Required;

$form = Form::new(
    Input::new('name')
        ->withTitle('What is your name?')
        ->withValidator(new Required())
);

echo $form->view();

What's in the box

Input primitivesTextInput, TextArea, ItemList, Viewport, FilePicker, Cursor, Scrollbar, Spinner.
Form engineField interface + Field{Input, Text, Confirm, Select, MultiSelect, Note, FilePicker, Date, Slider, Color}, Form, Group, KeyMap, Theme.
Hidden fields & groupsForm honours Field::isHidden() in values, errors, validation, navigation, submit and view; focus never rests on a hidden field and fully hidden groups are skipped. A Group::withHideFunc() predicate sees the same view values() returns — the visible fields of every visible earlier group.
Bounded editingTextInput / TextArea clip a paste or insert to the remaining charLimit budget (newlines count), and TextArea pans to keep the cursor row visible.
ValidatorsRequired, Email, MinLength, MaxLength, Pattern — pluggable validator interface.
Fuzzy matchingFuzzy\FuzzyMatcher with Smith-Waterman algorithm for filter-as-you-type in Select/MultiSelect.

Use it for

Source & demos

Try the quickstart →

API

ClassMethodDescription
Formnew(Field ...$fields)Create a single-group form with fields
Formgroups(Group ...$groups)Create a multi-page form
Formvalues() / getString() / getInt() / getBool() / getArray()Submitted values of visible fields; hidden fields and hidden groups are excluded
Groupnew(Field ...$fields) / withHideFunc(?\Closure(array): bool)A page of fields; the predicate receives the visible values collected before this group
Field\Inputnew(string)Create a text input field
Field\Confirmnew(string)Create a confirmation field
Field\Selectnew(string)->withOptions(string ...)Create a select field
Validator\Requiredvalidate(mixed)Check value is not empty
Validator\Emailvalidate(mixed)Check valid email format
Spinner\Spinnernew(?Style)Create a spinner with style

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

CandyForms demo

Form primitives

TextInput, TextArea, Select and more — the foundation components.