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

Required Fields for @rjsf/antd #3743

Open
4 tasks done
georgiossalon opened this issue Jun 26, 2023 · 2 comments
Open
4 tasks done

Required Fields for @rjsf/antd #3743

georgiossalon opened this issue Jun 26, 2023 · 2 comments
Labels

Comments

@georgiossalon
Copy link

georgiossalon commented Jun 26, 2023

Prerequisites

What theme are you using?

antd

Version

5.8.2

Current Behavior

Input fields that are set as required by the scheme are missing the required property in the browser.

In the following code, if you switch to the MaterialUI or the default Form component you do get the expected result. When using the antd Form component via the withTheme you don't.

Here is a dummy Form:

import React, {createRef} from "react";
import "./App.less";
import {withTheme} from "@rjsf/core";
import Form from '@rjsf/material-ui';
import validator from "@rjsf/validator-ajv8";

import {Theme as AntDTheme} from '@rjsf/antd';
import {Popconfirm} from "antd";

const RJSFForm = withTheme(AntDTheme);

const uiSchema = {
    "ui:disabled": false,
    "ui:order": [
        "Name1",
        "Number 1",
    ],
    Name1: {
        "ui:disabled": false
    },
    "Number 1": {
        "ui:disabled": false
    },
};

const schema = {
    type: "object",
    $schema: "http://json-schema.org/draft-07/schema#",
    required: ["Name1"],
    "ui:order": [
        "Name1",
        "Number 1",
    ],
    properties: {
        "Name1": {
            type: "string"
        },
        "Number 1": {
            type: "number",
            default: 0
        },
    },
    $id: "http://json-schema.org/draft-07/schema#"
};

function App() {
    const formRef = createRef();
    const submitRef = createRef();
    const onError = (errors) => console.log(errors);

    return (
        <div className="App">
            <RJSFForm
                schema={schema}
                uiSchema={uiSchema}
                validator={validator}
                onError={onError}
                ref={formRef}
                formData={{
                    "Number 1": 0,
                }}
            >
                <button hidden={true} ref={submitRef}/>
            </RJSFForm>
            <button
                onClick={() => {
                    submitRef.current.click();
                }}
            >
                submit
            </button>

        </div>
    );
}


export default App

Expected Behavior

In the browser, the input tags should get the required property when the set into the schema.

Steps To Reproduce

Sandbox: CodeSandbox

Environment

- OS: -
- Node: v16
- npm: v8

Anything else?

No response

@georgiossalon georgiossalon added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jun 26, 2023
@nickgros
Copy link
Contributor

Here's a playground link. The antd UI indicates that the field is required, and Ajv validation works as expected. The main difference that I see is that the antd theme is missing HTML5 validation.

@nickgros nickgros added help wanted antd antd related theme issue validation and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jun 30, 2023
@georgiossalon
Copy link
Author

@nickgros Yeah, the field looks like it would be a required one but in the input tag, the required property is missing. The same applies to your playground link.

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

2 participants