java-bean-validation.js
Version:
Java Bean Validation implementation for JavaScript
72 lines • 2.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("../core/core");
var visit_1 = require("../core/visit");
var lookup_1 = require("./lookup");
function getHtmlInputType(propertyOrTypeOrTypeName, propertyName, groups, violations) {
if (groups === void 0) { groups = core_1.DEFAULT_GROUPS; }
if (violations === void 0) { violations = []; }
var property = lookup_1.lookupPropertyDescriptor(propertyOrTypeOrTypeName, propertyName, undefined, '', violations);
if (!property) {
return null;
}
var htmlInputType = property.htmlInputType;
if (htmlInputType !== undefined) {
return htmlInputType;
}
var inputType = null;
var visitor = {
startConstraintVisitor: function (constraint) {
switch (constraint.constraintName) {
case 'String':
if (!inputType) {
inputType = 'text';
}
break;
case 'Boolean':
inputType = 'checkbox';
break;
case 'IntegerNumber':
inputType = 'number';
break;
case 'FloatNumber':
inputType = 'float';
break;
case 'Date':
inputType = 'date';
break;
case 'Time':
inputType = 'time';
break;
case 'Timestamp':
inputType = 'datetime';
break;
case 'Email':
inputType = 'email';
break;
case 'URL':
inputType = 'url';
break;
case 'Multiline':
inputType = 'textarea';
break;
case 'Password':
inputType = 'password';
break;
case 'PhoneNumber':
inputType = 'tel';
break;
case 'Money':
inputType = 'money';
break;
}
return true;
},
ignoreValue: true
};
visit_1.visitPropertyDescriptor(property, propertyName, undefined, '', groups, violations, violations, visitor);
property.htmlInputType = inputType;
return inputType;
}
exports.getHtmlInputType = getHtmlInputType;
//# sourceMappingURL=getHtmlInputType.js.map