Skip to content

nvxdm/strapi-plugin-remote-select

Repository files navigation

Remote select

🎉 Supports Strapi 4 and Strapi 5 🎉

A powerful tool that adds select type inputs to your strapi with the ability to dynamically load options via API. Supports static and searchable endpoints—autocomplete. This module adds two inputs:

Remote select, allow selecting one or several values from the remote options endpoint. Searchable select, allow selecting one or several values from the searchable remote endpoint.

Features (all selects support remote options loading):

  • plain select
  • multi select
  • searchable select, single model
  • searchable select, multiple model

💭 Motivation

Too often I've had situations where I need to allow selecting one or more values from a list that is available as an API. Simply transferring the value is not an option, as the values can change dynamically on the remote resource, and the native Select has the same value as the one displayed to the user, which is not always convenient. That's why I was inspired to create this module, which solves this problem, you just need to add the desired input and configure it and that's it, you will always get the latest options, and the ability to use the searchable API or auto-complete significantly expands the use cases for this module.

⚠️ Requirements

Strapi version Requirements
Strapi 5 "node": ">=18.0.0 <=20.x.x" "@strapi/strapi": "^5.2.0"
Strapi 4 "node": ">=18.0.0 <=20.x.x" "@strapi/strapi": "^4.24.5"

🔃 Versions

This plugin supports several strapi versions, use this table to choose the correct one for your strapi version

Strapi 4 Strapi 5
1.x.x 5.x.x

⏳ Installation

# using yarn
yarn add strapi-plugin-remote-select

# using npm
npm install strapi-plugin-remote-select --save

Enable plugin in your config/plugins.js file, just add:

module.exports = {
  'remote-select': {
    enabled: true,
  },
};

🪄 Usage

Each input select that this plugin adds has a similar configuration:

Basic settings

Note on labels: You can generate option labels either by extracting a single field via JSONPath or by composing multiple fields using template syntax ({{ field }}). Supports dot-path access for nested properties (e.g., {{ address.city }}). See the table below and examples afterward.

Module is using JSON path for allow configurable way to get an option array, label, and value for options objects. Learn more about JSON path here

Field name Type Description
Fetch options url string A url for fetch options for select. Endpoint should return a valid json string as response
Fetch options method string HTTP method for requesting options. Default: GET
Fetch options request body string HTTP body for requesting options. Provide a your custom body for options fetching.
Fetch options request custom headers string Custom fetch options request headers in raw format, one header per line. For example: Content-type: application/json
JSON path to options array string $ - here it is the body answer to the options request
JSON path to label for each item object string JSON path or template to generate label. Use JSON path (e.g., $.title) to extract a single field, or template syntax to combine multiple fields (e.g., {{ title }} - {{ category }}). Supports nested access (e.g., {{ address.city }}). $ represents each option item selected from "JSON path to options array"
JSON path to value for each item object string $ - here it is the each options item selected from "JSON path to options array"

Advanced settings:

Field name Type Description
Default value string
Multi mode string
Private field string

Variables in API Requests

The plugin now supports using variables in your API URLs, headers, and request bodies. This allows for dynamic configuration of your API requests.

Setting up variables

Add variables to your plugin configuration in config/plugins.js:

module.exports = {
  "remote-select": {
    enabled: true,
    config: {
      variables: {
        apiBaseUrl: "https://api.example.com",
        apiVersion: "v2",
        authToken: "your-auth-token",
      },
    },
  },
};

Using variables

You can use variables in your configuration using the {{ variableName }} template syntax (same as label templates):

  • In API URLs: {{ apiBaseUrl }}/products/{{ apiVersion }}/list
  • In request headers: Authorization: Bearer {{ authToken }}
  • In request bodies: { "version": "{{ apiVersion }}" }

Variables provide a convenient way to:

  • Manage environment-specific API endpoints
  • Share authentication tokens across multiple select configurations
  • Update common values in one place instead of modifying each select configuration

Configuration Presets

Presets allow you to define reusable fetch configurations in your plugin config and reference them by name when configuring fields. This keeps API details (URLs, tokens, mapping) in one place — instead of duplicating the same configuration across multiple fields, you just select a preset by name. Secrets (API keys, tokens) stay server-side and are never exposed to the browser.

Defining presets

Add a presets object to your plugin configuration. Each key is the preset name, and the value contains the fetch and mapping settings.

TypeScript (config/plugins.ts):

import { RemoteSelectPluginOptions } from 'strapi-plugin-remote-select/dist/server';

export default () => ({
  'remote-select': {
    enabled: true,
    config: {
      variables: {},
      presets: {
        'get-products': {
          fetch: {
            url: 'https://dummyjson.com/products',
            method: 'GET',
          },
          mapping: {
            sourceJsonPath: '$.products.*',
            labelJsonPath: '$.title',
            valueJsonPath: '$.id',
          },
        },
      },
    } as RemoteSelectPluginOptions,
  },
});

JavaScript (config/plugins.js):

module.exports = ({ env }) => ({
  'remote-select': {
    enabled: true,
    config: {
      variables: {
        authToken: env('API_AUTH_TOKEN'),
      },
      presets: {
        'get-products': {
          fetch: {
            url: 'https://dummyjson.com/products',
            method: 'GET',
          },
          mapping: {
            sourceJsonPath: '$.products.*',
            labelJsonPath: '$.title',
            valueJsonPath: '$.id',
          },
        },
        'search-users': {
          fetch: {
            url: 'https://api.example.com/users/search?q={{ q }}',
            method: 'GET',
            headers: {
              'Authorization': 'Bearer {{ authToken }}',
            },
          },
          mapping: {
            sourceJsonPath: '$.users',
            labelJsonPath: '$.name',
            valueJsonPath: '$.id',
          },
        },
      },
    },
  },
});

Preset options

Each preset has fetch and mapping sections:

fetch — request configuration:

Field Type Default Description
url string Required. The API endpoint URL
method string GET HTTP method (GET, POST, or PUT)
body string Request body (for POST/PUT requests)
headers Record<string, string/number> Headers as key-value object (e.g., { Authorization: 'Bearer {{ authToken }}' })

mapping — response mapping:

Field Type Default Description
sourceJsonPath string $ JSONPath to the options array in the response
labelJsonPath string $ JSONPath or {{ template }} for the option label
valueJsonPath string $ JSONPath for the option value

Using presets

When configuring a remote-select or searchable-remote-select field in the content-type builder, select a preset from the Preset dropdown (or type a preset name if no presets are loaded). When a preset is selected, the custom fetch configuration fields below are ignored — all settings come from the preset.

For searchable presets, use {{ q }} in the URL or body — the search term will be substituted server-side at request time.

Remote select input

Depends on multi option you will have in the model a single string from selected value option or array of selected value string.

Basic configuration window:

Remote select settings window

for example, let's consider the next api endpoint 'https://dummyjson.com/products' with response structure:

{
  "products": [
    {
      "id": 1,
      "title": "Essence Mascara Lash Princess",
      "description": "The Essence Mascara Lash Princess is a popular mascara known for its volumizing and lengthening effects. Achieve dramatic lashes with this long-lasting and cruelty-free formula.",
      "category": "beauty",
      "price": 9.99,
      "discountPercentage": 7.17,
      "rating": 4.94,
      "stock": 5
    },
    {
      "id": 2,
      "title": "Eyeshadow Palette with Mirror",
      "description": "The Eyeshadow Palette with Mirror offers a versatile range of eyeshadow shades for creating stunning eye looks. With a built-in mirror, it's convenient for on-the-go makeup application.",
      "category": "beauty",
      "price": 19.99,
      "discountPercentage": 5.5,
      "rating": 3.28,
      "stock": 44
    }
   ]
}

Configured remote select window will look like that: We are going to use id field from a product object as value and title field as label.

Label examples:

  • JSONPath: set label path to $.title
  • Template: set label path to {{ title }} - {{ category }}

Remote select example configured settings window

and as a result, we have: (single mode)

Remote select single input

multiple mode:

Remote select multi input

Searchable remote select input

Depends on multi option you will have in the model a JSON string with the object:

{
  "label": "Label from option",
  "value": "Value from option"
}

or JSON string with the array of objects:

[
  {
    "label": "Label from option",
    "value": "Value from option"
  },
  {
    "label": "Label from option",
    "value": "Value from option"
  }
]

Basic configuration window: It's the same as in Remote select input:

Remote select settings window

for example, let's consider the next api endpoint with search ability 'https://dummyjson.com/products/search?q=searchphrase' with the same response structure like as in Remote select example.

Configured remote select window will look like that:

Searchable remote select configured window

and as a result, we have: (single mode)

Searchable remote select single

multiple mode:

Searchable remote select multi input

About

A powerful tool that adds select type inputs to your strapi with the ability to dynamically load options via API. Supports static and searchable endpoints—autocomplete.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors