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

GenericInput: pass disabled to JSONInput #16030

Closed
alvarolozano opened this issue Mar 8, 2023 · 1 comment · Fixed by #16033
Closed

GenericInput: pass disabled to JSONInput #16030

alvarolozano opened this issue Mar 8, 2023 · 1 comment · Fixed by #16033
Labels
issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:content-manager Source is core/content-manager package status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@alvarolozano
Copy link
Contributor

Bug report

Required System information

  • Node.js version: 14.18
  • NPM version: 6.14.5
  • Strapi version: 4.7.1
  • Database: Postgres/Sqlite
  • Operating system: Ubuntu based distro
  • Is your project Javascript or Typescript: JavaScript

Describe the bug

The GenericInput component does not currently pass the disabled attribute to the JSONInput component, so for advanced use cases, it is not possible to achieve a readonly JSON field

Steps to reproduce the behavior

  1. Generate a new UI component
  2. Add a genericInput with type="json" and disabled={true} and other required props
  3. The field renders correctly, but it is not disabled, you are able to edit it

Expected behavior

When a json type genericInput renders the component, the disabled attribute should be passed to the child JSONInput, so it's possible to achieve a readonly field

Screenshots

Code snippets

// helper-plugin/lib/src/components/GenericInput/index.js
switch (type) {
    case 'json': {
      return (
        <JSONInput
          label={label}
          labelAction={labelAction}
          value={value}
          error={errorMessage}
          hint={hint}
          required={required}
          onChange={(json) => {
            // Default to null when the field is not required and there is no input value
            const value = !attribute.required && !json.length ? 'null' : json;
            onChange({ target: { name, value } });
          }}
          minHeight={pxToRem(252)}
          maxHeight={pxToRem(504)}
        />
      );
    }

Additional context

Add any other context about the problem here.

@alvarolozano
Copy link
Contributor Author

alvarolozano commented Mar 8, 2023

I could fix it! So If PRs are accepted, I would contribute it

@joshuaellis joshuaellis added issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve status: confirmed Confirmed by a Strapi Team member or multiple community members source: core:content-manager Source is core/content-manager package labels Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:content-manager Source is core/content-manager package status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
Status: Fixed/Shipped
Status: Fixed/Shipped
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants