GithubHelp home page GithubHelp logo

Comments (3)

tidoust avatar tidoust commented on May 14, 2024

Hi @Anthropic,

In your proposal, what happens when the form gets submitted with what you call a legacy value?

  1. Should the schema be automatically adjusted to accept the incorrect value?
  2. Should the submission trigger an error because the schema is not respected?

Option 1. does not sound quite right. What good is a schema if the code can decide to change it on its own? If you expect the unexpected values, the best would be to define the field as a regular string in the schema and to define the base enumeration in the form part. I do not know whether the enumeration is going to work as-is if it is defined that way though (I haven't checked). The good part is that doing so lets us move from option 1 to option 2, as the schema does not need to be automatically adjusted anymore.

Option 2. can be implemented with a custom field, I think. In other words, there should not need to be any change to the core of the JSON Form library. Just take the code of the select field type as basis to create a new extensibleselect (or some better name) that would create the appropriate markup for you.

One thing I would do differently is that I would not use a property legacyClass but rather a allowUndefinedValues flag or similar. The generated markup would still mark the unknown values with a specific class undefined-value for styling purpose. You would lose the ability to specify a custom class but would be more explicit about what you're trying to achieve.

I am not really sure this possibility needs to be supported by JSON Form. It sounds rather specific. Do others have similar needs?

from jsonform.

Anthropic avatar Anthropic commented on May 14, 2024

@tidoust ok I think you gave me an easier way (perhaps) to get the solution I am after!

If the schema was a plain string with no enum, then if I could define the enum at the form level using the already included titleMap field instead, it could allow for additions. In that way it could double as a suggestion list rather than a hard list were it set to text in the form definition perhaps.

I can imagine uses for a suggestion list on a form field beyond my current use case.

{
    schema: {
        enemies: {
            title: "Scariest Enemy!",
        }
    },
    form: [
        {
            key: "enemies",
            type: "select",
            titleMap: {
                dragon: "The Dragon",
                pirate: "Jack Sparrow",
                alien: "ALF"
            },
            // template for undefined value label
            undefined: "[legacy] {{value}}"
        }
    ],
    value: {
        enemies: "ninja"
    }
}

At the moment when I do the above I get a select box with nothing in it, if it could add the titleMaps values as options when no enum is defined, then my problem would be solved. :)

Obviously I could just add the option to the schema or titleMaps prior to initialising, but that doesn't feel right.

from jsonform.

tchapi avatar tchapi commented on May 14, 2024

Closing as there is no activity on this issue. Please reopen a new one if needed.

from jsonform.

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.