Code Monkey home page Code Monkey logo

react-json-form's Introduction

react-json-form

React Component for editing JSON data using form inputs.

npm badge

Live demo

https://bhch.github.io/react-json-form/playground/

Documentation

https://bhch.github.io/react-json-form/

⚠️ Important notes

  1. Consider this library as a work-in-progress (at least until version 3 which will be a more stable release).
  2. Currently, this library doesn't provide default CSS styles. So, you're required to write your own CSS styles. You can also copy the styles from the demo page (see docs.css after Line 433) as a starting point.
  3. Be prepared for breaking changes regarding UI structure and CSS class names. Currently, CSS class names don't follow a particular naming standard. But this will change in v3.
  4. Support for UI themes will be added soon.

react-json-form's People

Contributors

bhch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-json-form's Issues

Initial blank data for certain field types (number, boolean, etc.) is not being set

Initial blank data is not being set for numbers and boolean (and possibly others). This leads to this error:

Warning: A component is changing an uncontrolled input to be controlled.
This is likely caused by the value changing from undefined to a defined value, which should not happen.
Decide between using a controlled or uncontrolled input element for the lifetime of the component.

Choices for boolean type don't return boolean values

HTML (or browsers?) always returns a string value from an input. However, this library should convert the type as per the type keyword.

For example, something like this should return a boolean value:

{
    type: 'boolean',
    choices: [
        {label: 'Yes', value: true},
        {label: 'No', value: false},
    ]
}

This seems to work properly for number type: even though the browser returns a string, the values are converted to number.

FormDateTimeInput component listens for all click events even when the time selector is hdden

Once the FormDateTimeInput component mounts, it starts listening for all click events. This is to close the time selector popup when a user clicks outside. But this also listens for click events even when the time selector is hidden. This seems bad for performance.

The component should only listen for click events while the time selector is visible/mounted. The solution is to move the click event listening code down to the time selector popup.

Add support for "date-time" format.

Currently datetime format is support, however the Standard JSON Schema spec has date-time.

So, add support for date-time and make datetime an alias.

CSRF Token missing in cookie while admin's changeform

First of all, thank you for the library, it is really helpful.

I am trying to upload a file following your tutorial in the documentation. However, I am facing an error of Permission Denied due to missing CSRF token.

I am using the JSONField in django's admin changeform. While going through your code, I noticed that you are retrieving the CSRF token from cookie as stated here. However, in admin changeform or while using the middleware django.middleware.csrf.CsrfViewMiddleware a hidden HTML field with name csrfmiddleware is added and no csrftoken token is set in the cookie.

As a workaround, I have set the cookie manually in my js file:

document.cookie = "csrftoken=" + $("input[name=csrfmiddlewaretoken]").val()

Then everything works as expected.

To resolve this I propose to modify getCsrfCookie function to check for the csrfmiddleware field or cookie before returning null.

Support for more validation keywords

Array

  • uniqueItems

String

  • minLength
  • maxLength
  • required

Number / Integer

  • minimum
  • maximum
  • exclusiveMinimum
  • exclusiveMaximum
  • multipleOf
  • required

Boolean

  • required

Initial data is not updated on the FormInstance

FormInstance's data is only updated in the onChange method. But the initial data (which is returned after syncing the data with schema) is not sent to FormInstance. Hence, calling getData() returns stale data.

Example:

var form = reactJsonForm.getFormInstance(...);

form.getData(); // -> returns stale/unsynced data if a change event hasn't occurred yet

Delete unsaved uploaded files

Since the upload of the file is done through Ajax call to an endpoint specified in Django settings.JSONFORM_UPLOAD_HANDLER, then there might be a case where the client would upload and close the page or cancel saving the model and the files would be still be uploaded without any link to a record in the database. In this case, how would you remove these uploaded files.

Proposal:

One way I can think of, is when a file is successfully uploaded, then in the .then((result) we store the returned file name in a list in react, and upon exit of page without saving (like explained here), if the list is not empty, then we send a DELETE to settings.JSONFORM_UPLOAD_HANDLER to delete those files. The clear button should as well send DELETE.

In this case, the handler endpoint should deal with both POST and DELETE methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.