icon Multiple Choice

The Multiple Choice field allows to select one or more options from a predefined list of options.

This page contains a detailed description of the field properties and JavaScript samples which you can use with this field.

Multiple Choice field

Common Properties

Multiple Choice Properties

Here you can find properties specifically related to the Multiple Choice field.

Data source

Select the source which is used to populate the field with options in the Source property.

Opened Source property with available sources

Static list

Define available field options directly in the form.

Click inside the Options property to edit available options:

Static list options

Add new options and edit option names and colors. Optionally, specify the default option:

Options editor dialog with custom options added and with a default option selected

Enable Allow user value to let users enter a custom value that isn’t included in the list of options:

Allow user value

Excel

Get available field options from an Excel file stored in your OneDrive. You can dynamically update this file with data from an SQL database, Dynamics 365, or any other source using Power Automate.

To retrieve options from an Excel file:

  1. Click the account icon in the Account property and connect your OneDrive account.

    Account property with the connect button
  2. Select the path to the Excel file in the File property.

    File property
  3. If there are multiple sheets in the Excel file, select which Sheet to use. The first sheet is selected by default.

    Sheet property
  4. If the data is formatted as a table, select the table name in the Table property. Otherwise, the property is not available and you can skip this step.

    Table property
  5. Select the column to label field options in the Text column property.

    Text column property

  6. In the Value column property, specify the column whose values are saved when the form is submitted. These values will be used in Power Automate or Zapier.

    Value column property

  7. In the Caching property, specify how long the data is cached. If a user refreshes the form page within this time, it uses the cached data instead of loading it from OneDrive.

    The data is stored for 600 seconds (10 minutes) by default.

    Caching property

  8. Click More options to access the Extra columns property.

    Access Extra columns property

    Use this property to specify what other columns you want to retrieve from Excel.

    Extra columns property

    These columns aren’t visible in the form, but can be retrieved in JavaScript.

SharePoint

Get available options from a SharePoint list or library.

  1. Fill in the Site URL property with your SharePoint site URL and click the check mark to connect to it.

    Site URL property

    When you connect Plumsail Forms to SharePoint for the first time, you will be prompted to grant Plumsail Forms access to your tenant.

    Note

    If you don’t want to give Plumsail Forms tenant-wide permissions, learn how to grant access to selected sites only.

  2. Select the list or library you want to take options from in the List property.

    List property
  3. Choose the column to label options in the Text column property.

    Text column property

  4. Choose the column to define option values in the Value column property. These values are saved to form submissions.

    Value column property

  5. Specify how long the data is cached in the Caching property. If a user refreshes the form page within this time, it uses the cached data instead of loading it from SharePoint.

    The data is stored for 600 seconds (10 minutes) by default.

    Caching property

  6. Click More options to access the Extra columns property.

    Access Extra columns property

    Use this property to specify what other columns you want to retrieve from your SharePoint list or library.

    Extra columns property

    These columns aren’t visible in the form, but can be retrieved in JavaScript.

Columns

Specify the layout of the options. By default, the options are grouped into three columns.

Columns property

JavaScript framework

In this section, you can find basic examples of how to work with the field using JavaScript.

For more examples, check out Working with form fields in JavaScript article. If you are not familiar with the JavaScript framework, get started with the JavaScript basics.

Note

The field is only accessible once the form is rendered, so all calls to the field must be inside fd.rendered event:

fd.rendered(() => {
    // make field required
    fd.field('Field1').required = true;
});

Wait until field is ready

Wait until the field is loaded. The ready method returns a promise that is resolved when the field has been fully initialized and is ready to work with.

Useful if loading data from Excel data source.

fd.field('Field1').ready(field => {
    // alert when the field is ready
    alert('Field is fully loaded');
});
// or
fd.field('Field1').ready().then(field => {
    // alert when the field is ready
    alert('Field is fully loaded');
});

Get or set field value

Get or set the Multiple Choice field value:

// get field value as an array of strings
fd.field('Field1').value;

// set field value
fd.field('Field1').value = ['Item 1', 'Item 2'];

Handle change event

Execute a function when a field value changes:

fd.field('Field1').$on('change', value => {
    // log changes to browser's console
    console.log('New value: ' + value);
});

Make field required

Make a field required or optional:

// make field required
fd.field('Field1').required = true;

// make field optional
fd.field('Field1').required = false;

Disable field

Make a field non-editable. The field value can still be changed with JavaScript and saved:

// disable field
fd.field('Field1').disabled = true;

// enable field
fd.field('Field1').disabled = false;

Get HTML element

Access HTML element inside the field in order to modify it, hide it, or do something else.

// access field's control
let htmlElement = fd.field('Field1').$el;

// access field's block, which includes title and control
let htmlParentElement = fd.field('Field1').$parent.$el;

Hide field

Hide a field from a user. The field value can still be accessed and changed with JavaScript:

// hide field
fd.field('Field1').hidden = true;

// show field
fd.field('Field1').hidden = false;

Allow custom values

Define whether a user is allowed to enter a custom value that is not included in the list of options.

// turn on custom values
fd.field('Field1').allowUserValue = true;

// turn off custom values
fd.field('Field1').allowUserValue = false;

Change the text of the custom value option

Customize the text of the extra option that allows the user to enter a value that is not on the list of options. The default text is “Other”.

fd.field('Field1').customValueTitle = 'Enter your value';

Change field options

Change the Multiple Choice field options:

fd.field('Field1').options = ['New option 1', 'New option 2', 'New option 3'];

Get or set option colors

If you want to change option colors without changing the options, use the following, just replace Your option with actual value:

// get option colors
fd.field('Field1').optionsColors['Your option'].backgroundColor;
fd.field('Field1').optionsColors['Your option'].textColor;

// set option colors:
fd.field('Field1').setOptionColors('Your option', { textColor: '#ffffff', backgroundColor: '#ebb65e' });

Limit number of selectable options

You can limit the number of selectable options with field validation:

// prevent user from selecting more than 3 options
fd.field('Field1').addValidator({
    name: 'Field1 options validation',
    error: 'No more than 3 options',
    validate: value => {
        if (value.length > 3) {
            return false;
        }
        return true;
    }
});

Columns

Specify the number of columns by which the options will be grouped:

// group by 2 columns
fd.field('Field1').columnsNumber = 2;

Retrieve extra columns

To get values from an Excel or SharePoint data source extra columns property, use the following code:

let item = fd.field('Field1').selectedItem; // returns the object containing all columns of the first selected item
let items = fd.field('Field2').selectedItems; // returns an array for objects containing all columns of the selected items

To get values to populate other fields, check this example:

Excel extra columns populated other fields
// example use case
fd.rendered(() => {
    const officesField = fd.field('Offices');
    officesField.$on('change', value => {
        const officesData = officesField.selectedItems || [];
        fd.field('Countries').value = officesData.length
            ? officesData.map(office => office.Country).join('; ') + '; '
            : '';
    });
});