Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

netlify-cms-widget-async-select

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

netlify-cms-widget-async-select

An async select widget for netlify-cms which can populate entries from a valid endpoint. Allows for sending custom headers, data/value fields and transformations.

  • 1.3.2
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

netlify-cms-widget-select-async

Check out a demo!

A simple async select widget for netlify-cms which can populate entries from a valid endpoint. Allows for sending custom headers, data/value fields and transformations.

Install

As an npm package:

npm install --save netlify-cms-widget-async-select
import { Control as asyncSelectControl } from 'netlify-cms-widget-async-select'

CMS.registerWidget('async-select', asyncSelectControl)

Via script tag:

<script src="https://unpkg.com/netlify-cms-widget-async-select@^1.0.0"></script>

<script>
  CMS.registerWidget('async-select', window.asyncSelectControl, window.asyncSelectPreview)
</script>

How to use

Add to your Netlify CMS configuration:

    fields:
      - { 
          name: 'test_widget',
          label: 'Test Widget',
          widget: 'async-select',
          url: 'https://jsonplaceholder.typicode.com/users',
          valueField: 'id',
          displayField: 'name',
        },

Configuration

Async-select widgets may have the following properties in addition to the defaults used by netlity.


url - string - required

The URI of the endpoint which to request data to populate the select options.


valueField - string - required

Field in the data response which will be mapped to the value of the netlify widget once populated.


displayField - string - optional

default: valueField

Field in the data response which will be mapped to the display text of the netlify widget once populated.


dataKey - string - optional

default: valueField

Field in the data response which will be used for the source of the data.

For example, given the below data structure, you may set dataKey: 'data' to populate the select dropdown as expected.

Example:

{
    meta: {
        page: 1,
        total: 10
        ...
    }
    data: [{
        id: 1,
        name: 'user 1',
        email: 'foo@bar.com'
    },{
        ...
    }]
}

headers - object - optional

default: {}

Key-value object of HTTP headers to pass to the endpoint.

Example:

{
  'Content-Type': 'application/json',
  ...
}

method - string - optional

default: GET

HTTP request method to use when making call to endpoint.


body - optional

default: undefined

Body to send in request to endpoint.


filter - function - optional

default: undefined

Function which receives parameter entry (Immutable.js Map) which is run on each item returned from endpoint. Similar to Array.prototype.filter this will reject anything which does not return truthy.

Example:

filter: (entry) => {
  return entry.get('id') % 2;
}

Better documentation coming soon.

Support

For help with this widget, open an issue or ask the Netlify CMS community in Gitter.

Keywords

FAQs

Package last updated on 21 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc