Skip to content

v0.2.0

Choose a tag to compare

@etus-ephraitech etus-ephraitech released this 28 Oct 21:21
· 14 commits to master since this release

Multi-value fields, strict option checking, file uploads, layout, new inputs and custom field
types. Read "Upgrading from 0.1" in the README before upgrading.

Added

  • Multi-value fields: select()->multiple() (with size()) and a new checkboxes() group
    field. Both submit as name[] and validated() returns a list, empty when nothing is
    chosen.
  • eachRules() for rules checked against every item of a multi-value field, using
    CodeIgniter's name.* wildcard. permit_empty is added automatically so an empty list
    passes; use rules('required') to require at least one item.
  • New field_checkboxes view; views receive $inputName, $values and $multiple.
  • Strict option checking: submitted values for selects, multi-selects, radios, checkbox
    groups and single checkboxes must be among the field's options (for a checkbox, its checked
    value). Controlled by $strictOptions and $strictOptionsMessage in config, per field with
    ->strictOptions(bool) and ->messages(['options' => '...']). Errors survive
    redirect()->withInput().
  • Contracts\ChoiceFieldInterface (getAllowedValues(), getStrictOptions()) for custom
    fields with a fixed set of values; Form::usesStrictOptions().
  • File uploads: file() field with required(), multiple(), maxSize() (kilobytes),
    extensions(), mimes(), image() and maxDimensions(), mapped to CodeIgniter's file
    rules, plus a generated accept attribute. Optional file fields are only validated when a
    file is uploaded. Uploads are never part of validated(); get them with
    Form::getFile(), Form::getFiles() and Form::hasUploadedFile().
  • Forms with a file field are sent as multipart automatically.
  • After a failed submission, file fields show a "choose the file again" hint
    ($fileReselectMessage, theme class reselect), since browsers cannot refill them.
  • Contracts\FileFieldInterface for custom upload fields; new field_file view.
  • Theme templates missing from a theme's views folder fall back to the package's bundled copy
    of that theme, so views published before an upgrade keep working with new field types.
    php spark forms:publish adds the missing templates without touching customised ones.
  • Layout: row() places fields side by side and fieldset() groups them under a titled
    section (description(), id()); both nest and take addClass(). Fields and fieldsets get
    width(1-12) for their column inside a row; fields without a width share the row. Layout is
    defined in the form class and rendered by <?= $form ?> and fields(); fields themselves
    stay a flat list, so values, validation and field() are unaffected.
  • Form::getLayout(), Layout\Row, Layout\Fieldset; new layout_row and
    layout_fieldset views and theme classes row, column ({width} placeholder),
    column_auto, section, section_legend, section_description.
  • New inputs: time(), datetimeLocal(), color() (values lower-cased) and search().
    date(), time() and datetimeLocal() share min(), max() and step() through the new
    Fields\DateTimeInputField base class.
  • Custom field type registry: $fieldTypes = ['money' => MoneyField::class] in config makes
    $this->money('price') a builder method, including inline chaining and inside groups.
    Registrations are checked: camelCase names, no clashes with built-in types or Form
    methods, and classes must implement FieldInterface.
  • Form::addField($type, $name, $label) creates any built-in or registered field by type key;
    Form::hasFieldType(); Support\FieldTypes::BUILT_IN lists the built-in keys.
  • Custom fields can render their own view: a VIEW containing a path (fields/money or
    Vendor\Package\Views\money) is loaded as given instead of from the theme. Field views can
    ask $class() for any theme class key.

Changed

  • Behaviour change: strict option checking is on by default. A form that accepted values
    outside a field's options in 0.1 now rejects them. Set $strictOptions = false in
    app/Config/Forms.php to restore the 0.1 behaviour, or opt single fields out with
    ->strictOptions(false). Existing in_list rules keep working; they are now optional for
    option fields.
  • FieldInterface has three new methods: getEachRules(), isMultiple() and getWidth(). Custom fields
    extending Fields\Field get both automatically; classes implementing the interface
    directly must add them.
  • getOptionId() moved from Radio into the shared HasOptions trait.
  • fields() with no arguments now renders the form's layout (rows and fieldsets) instead of
    a flat list. fields('a', 'b') with names is unchanged. Published form.php views get
    layouts automatically.
  • The field_select view uses $inputName and $values. Re-publish the views
    (php spark forms:publish --force) or apply the same change if you customised it.

Fixed

  • An array posted to a single-value field (for example nickname[]=x) could pass validation
    on fields without rules and reach validated() as an array. Single-value fields now treat
    a posted array as no value, and an unticked checkbox's array counts as unticked.