Coder Social home page Coder Social logo

Comments (5)

n1k0 avatar n1k0 commented on May 2, 2024

There's the enumNames jsonschema property which allows defining labels for enums, though for booleans that'd mean having this property without an explicit enum defined (as it's implicit as [true, false]):

const schema = {type: "boolean", enumNames: ["Yes", "No"]};
const uiSchema = {"ui:widget": "radio"};

Odd, and unlikely to be used in existing JSON schemas out there...

Having a new ui:labels uiSchema property seems to be the simplest way to go:

const schema = {type: "boolean"};
const uiSchema = {
  "ui:widget": "radio", 
  "ui:labels": ["Yes", "No"]
};

We could also add support for options to widgets:

const schema = {type: "boolean"};
const uiSchema = {
  "ui:widget": {
    name: "radio", 
    labels: ["Yes", "No"]
  }
};

The latter would require a much larger internal refactoring and would be probably slightly more cumbersome to write, though the feature might be useful to other widgets as well (including custom ones).

Thoughts?

from react-jsonschema-form.

n1k0 avatar n1k0 commented on May 2, 2024

Thinking of it a little more, I could probably live with support provided by using enumNames right from the schema. As a bonus, the patch is a three liner.

const schema = {type: "boolean", enumNames: ["Yes", "No"]};
const uiSchema = {"ui:widget": "radio"};

from react-jsonschema-form.

n1k0 avatar n1k0 commented on May 2, 2024

@chmac quickly put a patch in #81 so we can stare at code. Would this be enough to you?

from react-jsonschema-form.

chmac avatar chmac commented on May 2, 2024

@n1k0 Certainly looks like it would do exactly what we want. Being able to pass in the values, like Yes / No would cover most cases where we'd have thought about building our own ui:widget.

from react-jsonschema-form.

n1k0 avatar n1k0 commented on May 2, 2024

Fixed by #81.

from react-jsonschema-form.

Related Issues (20)

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.