【发布时间】:2014-12-13 03:54:33
【问题描述】:
我一直在寻找一个非常简单的问题的答案,如何阻止用户在 Handsontable 的单元格中输入 250 个字符?我发现我可以重新创建验证,但这不会阻止用户输入超过 250 个字符。我正在寻找类似 maxlength 的东西:
<input id="notes" maxlength="250" />
var date_validator_regexp = /(^$|^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/][0-9]{4}$)/;
var limit_validator_regexp = /(^[\s\S]{0,250}$)/;
$("#gridUpdateNotes").handsontable({
startRows: 1,
startCols: 2,
colHeaders: ["Date", "Notes"],
columnSorting: false,
enterBeginsEditing: false,
autoWrapRow: true,
autoWrapCol: true,
minSpareRows: 1,
colWidths: [140, 450],
removeRowPlugin: true,
copyPaste: true,
afterValidate: function (isValid, value, row, prop, source) {
if (isValid == false && prop === "Notes") {
alert("The Notes cannot have more than 250 characters.");
}
},
columns: [
{
data: "NoteDate",
type: "date",
dateFormat: "mm/dd/yy",
allowInvalid: false,
validator: date_validator_regexp
},
{
data: "Notes",
allowInvalid: false,
validator: limit_validator_regexp
}
]
});
【问题讨论】:
标签: jquery handsontable