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

id and for are missing from input and label when using dependencies #803

Closed
2 tasks done
edi9999 opened this issue Jan 9, 2018 · 8 comments
Closed
2 tasks done
Labels

Comments

@edi9999
Copy link
Collaborator

edi9999 commented Jan 9, 2018

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

In some cases, the rendered DOM doesn't have ids for some fields. This has two issues :

  1. When clicking on the label, the input is not selected (since there is no binding between both)
  2. In development we get following stacktrace :
Warning: Failed prop type: The prop `id` is marked as required in `BaseInput`, but its value is `undefined`.
    in BaseInput (created by TextWidget)
    in TextWidget
    in Unknown (created by StringField)
    in StringField (created by SchemaField)
    in div (created by DefaultTemplate)
    in DefaultTemplate (created by SchemaField)
    in SchemaField (created by ObjectField)
    in fieldset (created by DefaultObjectFieldTemplate)
    in DefaultObjectFieldTemplate (created by ObjectField)
    in ObjectField (created by SchemaField)
    in div (created by DefaultTemplate)
    in DefaultTemplate (created by SchemaField)
    in SchemaField (created by Form)
    in form (created by Form)
    in Form (created by cloudAccountAdd)

Steps to Reproduce

  1. On the demo site : https://mozilla-services.github.io/react-jsonschema-form/
  2. Set UISchema and formData to {}
  3. Set JSONSchema to the following :
{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "type": "object",
  "properties": {
    "connector": {
      "type": "string",
      "enum": [
        "aws",
        "gcp"
      ],
      "title": "Provider",
      "default": "aws"
    }
  },
  "dependencies": {
    "connector": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "connector": {
              "type": "string",
              "enum": [
                "aws"
              ]
            },
            "key_aws": {
              "type": "string"
            }
          }
        },
        {
          "type": "object",
          "properties": {
            "connector": {
              "type": "string",
              "enum": [
                "gcp"
              ]
            },
            "key_gcp": {
              "type": "string"
            }
          }
        }
      ]
    }
  }
}

Expected behavior

I would expect to have a for= and an id= property on the input and label for key_aws and key_gcp

Actual behavior

No ids are present

See following GIF demosntrating the issue.

peek 2018-01-09 12-16

Version

1.0.0

@edi9999 edi9999 changed the title id and for are missing from input and label id and for are missing from input and label when using dependencies Jan 10, 2018
@edi9999
Copy link
Collaborator Author

edi9999 commented Jan 13, 2018

I still have this issue after updating to master.

It seems that this bug has not been fixed yet @redixhumayun

To reproduce, just run npm start after cloning the rjsf repository, then go to the "schema dependencies" demo, and enter something in the credit card input, you will see the same error

@edi9999 edi9999 reopened this Jan 13, 2018
@edi9999 edi9999 added the bug label Jan 13, 2018
@jacklp
Copy link

jacklp commented Jan 17, 2018

still finding this issue, after trying a few different configurations I found that fields that are inside a fixed array inside the dependencies object are also not being rendered on the page.

Please publish to npm when this is resolved <3

@redixhumayun
Copy link
Contributor

Hi, so I have a fix available for this by generating the idSchema in the ObjectField.js file. The reason I can't seem to do this in the Form.js file is because retrieveSchema seems to correctly set the new json schema only for the first level of a nested JSON object.

If you look at the following commit, I have added a second test to test_utils.js file within a describe.only block. Shouldn't this test be passing since retrieveSchema follows a recursive strategy to build a new schema object?

I have a potential fix, like I mentioned, in the Object.js file, however I am not sure this is a long term fix.

Was the original intention of the retrieveSchema function only to build the new schema one level deep? If so, maybe it would be better to refactor that function instead?

@jonathonlui
Copy link

@redixhumayun, I'd guess that generating the idSchema for the ObjectField inner fields is ok as it looks like ArrayField does something similar for its fields.

BTW, you're missing the formData argument in your toIdSchema call. I think it should be:

const newIdSchema = toIdSchema(schema, null, definitions, formData, idSchema["$id"]);

@redixhumayun
Copy link
Contributor

@edi9999 Take a look and let me know if this works - #819

@jipd
Copy link

jipd commented Mar 5, 2018

FYI: this bug only exists before a value is set for the element, once one has the id and htmlFor properties are available

jnorris-carecloud added a commit to CareCloud/react-jsonschema-form that referenced this issue Jul 2, 2018
* Fix rjsf-team#221: No validating but updating errorSchema base on array operation when live validation is off.

* Fix comparing

* Directly update errorSchema in onChange

* Typo fix (rjsf-team#737)

* Make form submission example clearer (rjsf-team#736)

In the example, the `onSubmit` function receives a `formData` obj. However, the actual data is in `formData.formData`. While this is explained in the docs, I propose making it clearer in the example as well.

* Update prettier to v1.8.2 (rjsf-team#756)

* fix: Pass `disabled` prop to `FieldTemplate`. (rjsf-team#741)

If you want to change how your FieldTemplate is rendered based on
ui:disabled, you currently have to check `uiSchema["ui:disabled"]`,
which is unlike the pattern for `readonly` and other known `ui:*`
settings.

* Fix issue rjsf-team#747 (rjsf-team#748)

* 66 enum no type (rjsf-team#668)

* Failing test for enum without type (rjsf-team#66 rjsf-team#611)

* Proposed fix for enum without type (rjsf-team#66 rjsf-team#611)

* PR feedback - getSchemaType function

https://github.com/mozilla-services/react-jsonschema-form/pull/668/files#r133395455

* Fix onAddClick signature in ArrayFieldTemplate (rjsf-team#775)

According to https://github.com/mozilla-services/react-jsonschema-form/blob/master/src/components/fields/ArrayField.js#L224 `onAddClick` is not returning function as specified in the documentation.

* fix typo in css code (rjsf-team#799)

* README: fix code snippet (rjsf-team#785)

* Generating idSchema based on dependency changes Fix rjsf-team#778 , Fix rjsf-team#803

* Add idPrefix option (Fix rjsf-team#796) (rjsf-team#806)

* Make .editorconfig valid (rjsf-team#807)

* typo (rjsf-team#811)

* Add span and class to label required symbol (rjsf-team#765)

* a priori should be italicized for readibility (rjsf-team#825)

* Priori should by prior, I think

* Italicizing a priori based on suggestion

* pass raw errors to  field widgets (rjsf-team#826)

* pass raw errors to  field widgets

* fixed formatting

* fixing line endings

* Pass raw errors into Field at creation; object destructuring; added test for passing of raw errors; removed unused prop from ArrayField.

* fix lineEndings

* Bump 1.0.1

* Move to the 3.x series of react-codemirror2 (rjsf-team#857)

* Move to the 3.x series of react-codemirror2

* Move to the 4.x series of react-codemirror2

See scniro/react-codemirror2#63 for more details.

* Pass formContext to ArrayFieldTemplate when rendering fixed array (rjsf-team#858)

* handle errors to correctly display schema errors in form (rjsf-team#864)

* Bump version 1.0.2

* Link to official JSON Schema site (rjsf-team#873)

* Updated README to mention the support from JSON Schema compliant drop-down enums (rjsf-team#882)

* Add passing of raw errors to ArrayField template and components (rjsf-team#876)

* Fixed multiplicative errors on schema dependencies (rjsf-team#884)

* Add idPrefix option (rjsf-team#883)

* Fix warning on FileWidget (rjsf-team#842)

* Update prettier and fix files (rjsf-team#892)

* Bump 1.0.3
@epicfaace
Copy link
Member

This seems to be fixed in the latest version (see playground), so I'm closing this.

@edi9999
Copy link
Collaborator Author

edi9999 commented Aug 11, 2019

Yes it works now !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants