react-jsonschema-form: [bootstrap-4] File uploads result in error ".file should match format "data-url""

Prerequisites

Description

Using the bootstrap-4 theme, submitting a file triggers an error:

.file should match format "data-url"

Steps to Reproduce

  1. Playground link
  2. Click “Choose file” for the first file upload
  3. Select any file from your computer
  4. Click “Submit”

Expected behavior

No errors are displayed.

Actual behavior

The following error is displayed:

.file should match format "data-url"

Version

master

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@Hasenn I worked around it using this:

I first created a widget in my repo called BootstrapFileWidget and reference the FileWidget from core:

import React from "react";
import FileWidget from "@rjsf/core/dist/cjs/components/widgets/FileWidget";

const BootstrapFileWidget = (props: any) => {
  return (
    <>
      <FileWidget {...props} type="file" />
    </>
  );
};

export default BootstrapFileWidget;

Then i popped that into the widgets

const widgets = {
  file: BootstrapFileWidget,
};

Then, made sure my file was using that widget:

const uiSchema = { file: { "ui:widget": "file" } }

Not the cleanest workaround, but it got me up in running in a few minutes

@tjuravich / @CKGrafico would you like to make a PR that fixes the bootstrap 4 file widget? 🙏

Super small update to @tjuravich great solution 😃

 <>
      <Form.Label className={props.rawErrors?.length > 0 ? 'text-danger' : ''}>
        {props.label || props.schema.title}
        {(props.label || props.schema.title) && props.required ? '*' : null}
      </Form.Label>
      <div className="form-control-file">
        <FileWidget {...props} type="file" />
      </div>
    </>

To have label like in bootstrap theme