简体   繁体   English

我可以在jsonschema形式的lib中为日期输入设置min和max属性吗?

[英]Can I set min and max attribute for a date input in jsonschema-form lib?

I'm using jsonschema-form lib and I would like to set a min and max date in my input field. 我正在使用jsonschema形式的 lib,我想在输入字段中设置一个最小和最大日期。 As explained in W3C documentation , in HTML5 min and max are attributes of input element. W3C文档中所述 ,HTML5中的min和max是输入元素的属性。

The JsonSchema I'm using is very simple: 我正在使用的JsonSchema非常简单:

{
  "title": "Date and time widgets",
  "type": "object",
  "properties": {
    "native": {
      "title": "Native",
      "type": "object",
      "properties": {
        "date": {
          "type": "string",
          "format": "date"
        }
      }
    }
  }

The UISchema is: UISchema是:

{
  "alternative": {
    "alt-date": {
      "ui:widget": "alt-date"
    }
  }
}

Can I set min and max attribute for a date input in the jsonschema-form lib? 我可以为jsonschema-form库中的日期输入设置min和max属性吗? If so, how can do it? 如果可以,该怎么办?

I just bumped into the same challenge and I agree this would be a nice capability. 我碰到了同样的挑战,我同意这将是一个不错的能力。 It looks like there is an active issue for adding support of validation: format[Exclusive](Minimum|Maximum) in a future draft of JSON Schema. 似乎在添加验证支持方面存在一个积极的问题:在JSON模式的未来草案中, format [Exclusive](Minimum | Maximum)

Meanwhile I plan to tackle this by by adding a small amount of JavaScript to set the attributes directly on the generated input elements, using either the generated id or a custom class . 同时,我计划通过添加少量JavaScript使用生成的id或自定义类直接在生成的输入元素上设置属性来解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM