FieldSet

  • FieldSet

    FieldSet adds repeatable rows to Jamroom forms. Use it when an item needs a list of related values, such as specifications on a Blog post or a list of labelled choices. Each row has the same fields, and users can add as many rows as the form allows.
  • Add a FieldSet in Form Designer

    Open Form Designer on the module’s create or update form.

    Add a field with the module’s usual prefix, such as blog_details for Blog. Give it a label such as Details, select field_set as the type, and enable it.

    Leave Field Options blank for Name and Value fields, or enter one of the function names below.

    Set Minimum and Maximum to control how many rows users can save. Leave Maximum blank for unlimited rows. Marking the field Required means at least one row must be entered.

    Save the field. If it should also appear on the corresponding create or update form, use Form Designer’s normal field linking.
  • Field Options

    Blank or ujFieldSet_pair_columns: Name and Value

    ujFieldSet_choice_columns: A label and an independent checkbox

    ujFieldSet_single_choice_columns: A label and a radio button for choosing one row from the list

    ujFieldSet_select_text_columns: A label, a size dropdown and an alternative text input


    On the form, select Add set to add a row. Use Remove to take it out and Undo removal to restore its values before saving. Drag a row or use Move up to change the order. Save the rows with the form’s usual submit button.
  • Display saved rows in a template

    The module that owns the form stores the rows, in order, as JSON in the field you created. In a Smarty template, use ujFieldSet_rows to read that field. This example displays the Name and Value entries from blog_details.
    <dl>
    {foreach $item.blog_details|ujFieldSet_rows as $row}
        <dt>{$row.name|escape}</dt>
        <dd>{$row.value|escape}</dd>
    {/foreach}
    </dl>
  • Define custom rows in PHP

    For Form Designer, supply a PHP callback that returns an array of column definitions and enter its name in Field Options. For a form built in PHP, pass the same array as columns when registering a field_set with jrCore_form_field_create().

    Supported column types are text, textarea, checkbox, radio, select, select_and_text and hidden. Columns can have their own labels, defaults and validation. Set unique to true to require distinct nonempty values within that column across the rows. A select can draw its choices from another FieldSet on the same form using options_field and options_column.

    Read submitted values through jrCore_form_get_save_data() and decode saved rows in PHP with ujFieldSet_decode_rows(). The module that owns the field controls access, storage and search. If you add a public FieldSet field to Jamroom Search, Search indexes the entire stored JSON value, including its keys. Keep private fields out of the search configuration.

Tags