Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@advanced-rest-client/form-data-editor

advanced-rest-client2.6kApache-2.03.0.10TypeScript support: included

An element to edit form data (x-www-form-urlencoded)

web-components, payload, payload editor, form data, www-url-form-encoded

readme

Published on NPM

Tests and publishing

<form-data-editor>

An element to edit form data (x-www-form-urlencoded).

The element renders a form that allows to enter form data values.

It may be used with AMF json/ld model via api-view-model-transformer to transform AMF model to the data view model.

<form-data-editor value="grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb" allowcustom allowdisableparams allowhideoptional></form-data-editor>

Usage

Installation

npm install --save @advanced-rest-client/form-data-editor

In an html file

<html>
  <head>
    <script type="module">
      import '@advanced-rest-client/form-data-editor/form-data-editor.js';
    </script>
  </head>
  <body>
    <form-data-editor allowcustom allowdisableparams></form-data-editor>
    <script>
    {
      const editor = document.querySelector('api-url-params-editor');
      editor.onchange = (e) {
        console.log('Payload value', e.target.value); // or e.detail.value
      };
      editor.onmodel = (e) {
        console.log('View model', e.target.model); // or e.detail.value
      };
    }
    </script>
  </body>
</html>

In a LitElement

import { LitElement, html } from 'lit-element';
import '@advanced-rest-client/form-data-editor/form-data-editor.js';

class SampleElement extends PolymerElement {
  render() {
    return html`
    <form-data-editor
      .value="${this.payloadValues}"
      .model="${this.viewModel}"
      @value-changed="${this._valueHandler}"
      @model-changed="${this._modelHandler}"></form-data-editor>
    `;
  }

  _valueHandler(e) {
    this.payloadValues = e.detail.value;
  }

  _modelHandler(e) {
    this.viewModel = e.detail.value;
  }
}
customElements.define('sample-element', SampleElement);

Behaviour controls

allowDisableParams

When set it renders a checkbox next to each for item that allows to disable the item. The item is in the view and in generated data mode but is ignored when producing the value.

allowCustom

When set is renders "add parameter" button and allows to create new form value. Mandatory for stand-alone use.

allowHideOptional

When item.required model property is not set and this value is set then it hides all optional items (not marked as required) and renders a checkbox to render hidden items in the view.

<form-data-editor allowhideoptional></form-data-editor>
<script>
{
  document.querySelector('form-data-editor').model = [
    {
      name: 'param1',
      value: 'value1',
      required: true
    },
    {
      name: 'param2',
      value: 'value2',
      required: false
    }
  ];
}
</script>

This editor renders only param1 parameter and hides param2 form item. The user can render hidden items at any time.

Generating view model from AMF model

You can produce the view model from model generated by AMF parser via api-view-model-transformer element. This element produces common model for query parameters, URI parameters, body, and headers.

<api-view-model-transformer></api-view-model-transformer>
<form-data-editor></form-data-editor>

<script>
{
  const api = await generateApiModel();
  const endpoint = '/api-endpoint';
  const operation = 'GET';
  const bodyParametersModelArray = getOperationRequestBodyFromModel(api, endpoint, operation); // some abstract method
  const transformer = document.querySelector('api-view-model-transformer');
  transformer.api = api; // This is required to compute ld+json keys!
  const viewModel = transformer.computeViewModel(bodyParametersModelArray);
  document.querySelector('form-data-editor').model = viewModel;
}
</script>

Development

git clone https://github.com/advanced-rest-client/form-data-editor
cd form-data-editor
npm install

Running the demo locally

npm start

Running the tests

npm test

API components

This components is a part of API components ecosystem

changelog

2.0.1 (2018-12-15)

Docs

Fix

2.0.0 (2018-05-21)

Docs

1.0.0 (2018-03-23)

0.2.5 (2017-12-14)

0.2.4 (2017-12-14)

Update

0.2.3 (2017-12-14)

Fix

New

0.2.2 (2017-07-30)

0.2.1 (2017-07-30)

0.1.5 (2017-06-18)

0.1.4 (2017-06-18)

Update

0.1.3 (2017-06-18)

0.1.2 (2017-06-18)

Fix

Update

0.1.1 (2017-06-18)

Docs

Update

3.0.0 (2019-08-19)

3.0.1 (2019-08-20)

3.0.2 (2019-08-30)

3.0.3 (2019-09-30)

3.0.4 (2019-10-01)

3.0.5 (2019-10-30)

3.0.6 (2019-11-11)

Bug Fixes

  • fix compatibility issues with anypoint-buttons [bump-version] (cea2b62)

3.0.7 (2019-11-20)

Build

  • bumping version c2638e0 by Pawel Psztyc
  • bumping version 54e3dd6 by Pawel
  • bumping version f1b472e by Pawel

Update

  • replacing icons in the editor element e15ef58 by Pawel Psztyc
  • adding sanitize option to arc-marked fed2f50 by Pawel Psztyc
  • upgrading dependencies 6b5e920 by Pawel

Bug Fixes

  • fix compatibility issues with anypoint-buttons [bump-version] cea2b62 by nicogon

Refactor

  • move styles into render (#5) [bump-version] ffbaaef by Francisco Di Giandomenico
  • replacing iron-icon with ARC icons bf16007 by Pawel Psztyc
  • deprecating legacy for compatibility 8c6e397 by Pawel
  • inlining buttons and adding content action slot 3987a83 by Pawel
  • 3.0.0 release (#2) cfc6dfb by Paweł Psztyć

Other

  • Fix: Fixing issue with hidden required properties. 63a3af7 by Pawel Psztyc
  • Docs: Updated readme file. eec0b21 by Pawel Psztyc
  • Docs: updated analysis file. ab1bd17 by Pawel Psztyc
  • Update: Updated dependency version c262f8a by Pawel Psztyc
  • Fix: Updated tests for new API 961c2fb by Pawel Psztyc
  • New: Added empty default value for the model. 80f6ffb by Pawel Psztyc
  • Fix: Supressed error when passing different than string value. f86eafb by Pawel Psztyc
  • Update: Replaced part of the logic with common behavior for the editors. c3a5052 by Pawel Psztyc
  • Update: Updated versions of thest helpers 694a477 by Pawel Psztyc
  • Update: Updated tests for recent changes in element's logic. b49dde3 by Pawel Psztyc
  • Fix: Fixed an issue when the model wasn't updated to reflec changes in the value when the element was disabled. 379c205 by Pawel Psztyc
  • Docs: Updated documentation for the element d757234 by Pawel Psztyc
  • Update: Added sauce connection to travis 3ad3a96 by Pawel Psztyc