GithubHelp home page GithubHelp logo

Comments (8)

tidoust avatar tidoust commented on May 15, 2024

Hi @Chris2m,

True. That's a limitation in current version. I don't have any good ETA for that feature. In the meantime, note that you may achieve a similar effect with the value property. Granted, it's rather meant to convey a previous submitted object, not default values.

For instance, instead of this:

{
  "schema": {
    "arr": {
      "type": "array",
      "items": {
        "type": "string",
      },
      "default": [
        "blah",
        "foo"
      ]
    }
  },
  "form": [
    "arr"
  ]
}

... you could do this:

{
  "schema": {
    "arr": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "form": [
    "arr"
  ],
  "value": {
    "arr": [
      "blah",
      "foo"
    ]
  }
}

from jsonform.

Chris2m avatar Chris2m commented on May 15, 2024

Hi @tidoust,

thanks for your response. I am aware of the value property for previously submitted values. Still, in my use case relying on default properties would be a really nice to have feature as I need to distinguish between default values and previously submitted values. I am using JSON Form to implement a configuration page for the backend of a web application.

Right now - building upon the current state of JSON Form - the only feasible solution seems to traverse the entire nested schema and find all the default values of type="array" and then mixin the previously submitted values which seems kind of hacky.

Let me know if I can be of any assistance in adding this feature.

Best,
Chris

from jsonform.

ulion avatar ulion commented on May 15, 2024

In above mentioned commit, it now support all level default values in the schema.

from jsonform.

tchapi avatar tchapi commented on May 15, 2024

It seems this is now implemented — please reopen if this is still an issue.

from jsonform.

iphoneintosh avatar iphoneintosh commented on May 15, 2024

Is this actually implemented / merged now? Seems like it still does not work on the latest main branch to use default values with arrays.

from jsonform.

TrangPham avatar TrangPham commented on May 15, 2024

It doesn't seem to work for me either

from jsonform.

sdetweil avatar sdetweil commented on May 15, 2024

@iphoneintosh @TrangPham yes, its implemented long time ago

else if (isSet(this.schemaElement['default'])) {
        // the value is not provided in the values section but the
        // default is set in the schemaElement (which we have)
        this.value = this.schemaElement['default']
        // We only apply a template if it's a string
        if (typeof this.value === 'string') {
          this.value = _.template(this.value, valueTemplateSettings)(formData);
        }

show the schema

from jsonform.

TrangPham avatar TrangPham commented on May 15, 2024

I'm using a reference and my default is set in the definitions like so:

{
    "TableColumnsToMatchOrderedListKwargs": {
        "title": "TableColumnsToMatchOrderedListKwargs",
        "type": "object",
        "properties": {
            "column_list": {
                "title": "Column List",
                "default": [
                    "vendor_id",
                    "pickup_datetime",
                    "dropoff_datetime",
                    "passenger_count",
                    "trip_distance",
                    "rate_code_id",
                    "store_and_fwd_flag",
                    "pickup_location_id",
                    "dropoff_location_id",
                    "payment_type",
                    "fare_amount",
                    "extra",
                    "mta_tax",
                    "tip_amount",
                    "tolls_amount",
                    "improvement_surcharge",
                    "total_amount",
                    "congestion_surcharge"
                ],
                "type": "array",
                "items": {
                    "type": "string"
                }
            }
        },
        "additionalProperties": false
    }
}```

would my default still be picked up?

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.