Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Polymer1.0两个输入的验证[类型=日期]_Javascript_Forms_Polymer 1.0 - Fatal编程技术网

Javascript Polymer1.0两个输入的验证[类型=日期]

Javascript Polymer1.0两个输入的验证[类型=日期],javascript,forms,polymer-1.0,Javascript,Forms,Polymer 1.0,我开始使用聚合物,但很多问题都找不到答案 我有两个输入 <paper-input id="startDate" type="date" error-message="The end date is before the start date"></paper-input> <paper-input id="endDate" type="date"></paper-input> 当两者都为空或仅填写一个时,该表单有效。如果两者都已填写

我开始使用聚合物,但很多问题都找不到答案

我有两个输入

<paper-input id="startDate" type="date" 
    error-message="The end date is before the start date"></paper-input>
<paper-input id="endDate" type="date"></paper-input>

当两者都为空或仅填写一个时,该表单有效。如果两者都已填写,则需要验证
endDate
是否大于或等于
startDate

如何做到这一点?

如果您刚刚开始,请阅读《开发人员指南》,在那里您可以找到大多数问题的答案

在您的情况下,您需要使用纸张输入的值声明属性,并观察其更改。在该观察器中,您可以编写逻辑并将任何(或两个)字段设置为无效

<dom-module id="my-form">
<template>
<paper-input id="startDate" type="date" value="{{startDate}}" error-message="The end date is before the start date"></paper-input>
<paper-input id="endDate" type="date" value="{{endDate}}"></paper-input>
</template>
<script>
(function() {
'use strict';

Polymer({
  is: 'my-form',

  properties: {
    startDate: Date,
    endDate: Date,
  },
  observers: ['_dateChange(startDate, endDate)'],
  _dateChange: function(startDate, endDate) {
     if(/*logic goes here*/) {
       this.$.startDate.invalid = true;
     } else {
       this.$.startDate.invalid = false;
     }
  }      
});
})();
</script>
</dom-module>

(功能(){
"严格使用",;
聚合物({
是‘我的表格’,
特性:{
开始日期:,
结束日期:日期,
},
观察员:[“日期变更(开始日期、结束日期)”,
_日期更改:函数(开始日期、结束日期){
如果(/*逻辑在此*/){
此.$.startDate.invalid=true;
}否则{
此.$.startDate.invalid=false;
}
}      
});
})();