日期验证器在验证检查后清除日期字段

时间:2017-05-20 05:19:28

标签: javascript angularjs angularjs-directive

我是angularjs和js的新手。我正在研究日期验证码,日期选择器。 下面是进行验证的代码。问题是,当我们选择一个日期并尝试更新它时会清除整个日期字段,如gif链接所示: - click here for date validation sample

下面的

是执行日期验证的代码。

id

我想要的是,当用户尝试更新日期字段时,日期字段不应为空。

-

这是带输入的html标签

/**
 * @ngdoc function
 * @name fromCriterion
 *
 * @description Converts a criterion's value into a value that can be used for the specified type of field.
 *
 * @param{String} criterion The criterion's string value, generally taken from the report state criteria
 * @param{String} type The type of the field which will use the criterion's value
 *
 * @returns{Object} The native object needed for a field, converted from a report criterion
 */
fromCriterion: function(criterion, type){
    if(angular.isDefined(criterion)){
        switch (type){
        case 'boolean':
            return criterion === '1';
        case 'compact_date':
            if (criterion.length > 9 && criterion.length < 11)
            return criterion !== "" && criterion !== "Invalid date" ? DateService.castTimeToUtcDate(moment(criterion, 'MMDDYYYY')): "";
        case 'inline_list':
        case 'inline_list_search':
            return criterion.split(',');
        case 'integer':
            return !_.isNaN(criterion) ? parseInt(criterion) : undefined;
        case 'iso_date':
            return criterion !== "" && criterion !== "Invalid date"  ? DateService.castTimeToUtcDate(moment(criterion, 'YYYY-MM-DD')): "";
        case 'suggest':
            return criterion.toString();
        default:
            return criterion;
       }
    }

    return undefined;
},

/**
 * @ngdoc function
 * @name toCriterion
 *
 * @description Converts the criterion value into a proper criterion string value,
 *              based on the type of the field that used the criterion.
 *
 * @param {Object} criterion The value of the field, which will be converted for
 *           storage within the report state criteria.
* @param {String} type The type of the field which interacted with the criteria.
*
 * @returns {String} The string which will be stored as a report criterion
 */
toCriterion: function(criterion, type){
                var parsedDate;
if (angular.isDefined(criterion)){
        switch (type){
        case 'boolean':
            return criterion ? '1': '0';
            break;
        case 'compact_date':
            return _.isDate(criterion) && criterion + "" !== "Invalid Date" ? DateService.formatDate(criterion, 'MMddyyyy'): '';
            break;
        case 'integer':
            return criterion ? criterion.toString() : '';
            break;
        case 'inline_list':
        case 'inline_list_search':
            return criterion.join();
            break;
        case 'iso_date':
            return _.isDate(criterion) && criterion + "" !== "Invalid Date" ? DateService.formatDate(criterion, 'yyyy-MM-dd'): '';
            break;
        case 'suggest':
            return parseInt(criterion);
            break;
        default:
            return criterion;
        }
    }

    return '';
}

下面是hh-report-field.js代码:

 <div name="communicationForm">
                  …
      …
                <hh-report-field field-name="MinContactDate" report-state-promise="reportStatePromise"></hh-report-field>
                 <hh-report-field field-name="MaxContactDate" report-state-promise="reportStatePromise"></hh-report-field>
             </div>

0 个答案:

没有答案