skip to Main Content

Is there a way to set the minimum date in the JSON Schema Form? With min it’s not working, here is an example:

{
  "title": "Date picker",
  "type": "object",
  "properties": {
    "native": {
      "title": "Title",
      "description": "description",
      "type": "object",
      "properties": {
        "date": {
          "type": "string",
          "format": "date",
          "default": "2023-10-26",
          "min": "2023-10-26"
        }
      }
    }
  }
}

Playground: https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJuYXRpdmUiOnsiZGF0ZSI6IjIwMjMtMTAtMjYifX0sInNjaGVtYSI6eyJ0aXRsZSI6IkRhdGUgcGlja2VyIiwidHlwZSI6Im9iamVjdCIsInByb3BlcnRpZXMiOnsibmF0aXZlIjp7InRpdGxlIjoiVGl0bGUiLCJkZXNjcmlwdGlvbiI6ImRlc2NyaXB0aW9uIiwidHlwZSI6Im9iamVjdCIsInByb3BlcnRpZXMiOnsiZGF0ZSI6eyJ0eXBlIjoic3RyaW5nIiwiZm9ybWF0IjoiZGF0ZSIsImRlZmF1bHQiOiIyMDIzLTEwLTI2IiwibWluIjoiMjAyMy0xMC0yNiJ9fX19fSwidWlTY2hlbWEiOnt9LCJ0aGVtZSI6ImRlZmF1bHQifQ==

2

Answers


  1. min is not a json schema keyword. minimum is, but it only works on numbers, not strings.

    In the currently-released versions of JSON Schema you can achieve some approximation to a minimum check by using regular expressions:

    description: at or later than 2023-10-26, up to 2099-12-31
    type: string
    format: date
    anyOf:
    - pattern: ^2023-10-2[6-9]
    - pattern: ^2023-1[12]
    - pattern: ^202[4-9]
    - pattern: ^20[3-9]
    
    Login or Signup to reply.
  2. I found this page and it helped –
    https://github.com/rjsf-team/react-jsonschema-form/issues/2118

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search