How to use the draftail.DraftUtils.createEntity function in draftail

To help you get started, we’ve selected a few draftail examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github springload / wagtailmodelchoosers / wagtailmodelchoosers / client / sources / RemoteModelSource.js View on Github external
const clone = {};
      fieldsToSave.forEach((field) => {
        clone[field] = data[field];
      });
      itemData = clone;
    } else {
      // Use the whole object.
      itemData = data;
    }

    const nextData = Object.assign({}, itemData, {
      id,
      label,
    });

    const nextState = DraftUtils.createEntity(
      editorState,
      type,
      nextData,
      nextData.label,
      entityMutability,
    );

    onUpdate(nextState);
  }
github springload / wagtailmodelchoosers / wagtailmodelchoosers / client / sources / ModelSource.js View on Github external
} else if (display in data && data[display]) {
        label = data[display];
      }

      if (label === undefined) {
        label = data[pkName];
      }
      entityMutability = 'IMMUTABLE';
    }
    const nextData = {
      id,
      label,
      content_type,
    };

    const nextState = DraftUtils.createEntity(
      editorState,
      type,
      nextData,
      nextData.label,
      entityMutability,
    );

    onUpdate(nextState);
  }
github springload / wagtaildraftail / wagtaildraftail / client / sources / GenericModelSource.js View on Github external
onSelected(id, data) {
        const { editorState, options, onUpdate } = this.props;
        const fieldName = options.display;
        const nextData = {
            id: id,
            label: data[fieldName],
            contentType: options.contentType,
        };

        const nextState = DraftUtils.createEntity(editorState, options.type, nextData, nextData.label, 'IMMUTABLE');

        onUpdate(nextState);
    }