Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden field in editor component is rendered #1405

Closed
papandreou opened this issue Jun 5, 2018 · 1 comment
Closed

Hidden field in editor component is rendered #1405

papandreou opened this issue Jun 5, 2018 · 1 comment

Comments

@papandreou
Copy link
Contributor

- Do you want to request a feature or report a bug?

bug

- What is the current behavior?

An editor component that declares a hidden field will have it rendered:

screen shot 2018-06-05 at 11 10 57

- If the current behavior is a bug, please provide the steps to reproduce.

  1. Declare an editor component that has a field with widget: 'hidden':
CMS.registerEditorComponent({
  // Internal id of the component
  id: "youtube",
  // Visible label
  label: "Youtube",
  // Fields the user need to fill out when adding an instance of the component
  fields: [{
    name: 'id',
    label: 'Youtube Video ID',
    widget: 'string'
  }, {
    name: 'myHiddenField',
    label: 'My hidden field',
    widget: 'hidden'
  }],
  // Pattern to identify a block as being an instance of this component
  pattern: /^youtube (\S+)$/,
  // Function to extract data elements from the regexp match
  fromBlock: function(match) {
    return {
      id: match[1]
    };
  },
  // Function to create a text block from an instance of this component
  toBlock: function(obj) {
    return 'youtube ' + obj.id;
  },
  // Preview output for this component. Can either be a string or a React component
  // (component gives better render performance)
  toPreview: function(obj) {
    return (
      '<img src="http://img.youtube.com/vi/' + obj.id + '/maxresdefault.jpg" alt="Youtube Video"/>'
    );
  }
});
  1. Add an instance of the component to a markdown editor.

Observe that the label for the hidden field is rendered with a No control for widget: 'hidden' message below it. The same thing happens if the hidden field has no label except that a small gray box is rendered instead of the label.

- What is the expected behavior?

That the field isn't rendered, similar to how hidden widgets work for collections.

- Please mention your versions where applicable.

Netlify CMS version: 1.8.4
Browser version: Chrome 67.0.3396.62/OSX

Node.JS version: 9.5.0
Operating System: OSX

- Please link or paste your config.yml below if applicable.

@erquhart
Copy link
Contributor

erquhart commented Jun 7, 2018

Good catch!

robertkarlsson pushed a commit to robertkarlsson/netlify-cms that referenced this issue Jun 8, 2018
Fixes decaporg#1405
Fields using hidden was rendered in the markdown editor with "no control" error if no label attached, else a grey box.
Return null when rendering the control for hidden widgets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants