:: Forum >>

Set input limit for grid row?

I need to limit the input length of a row in the grid to 140 chars, there is only one column, any way to do this? Thanks.
Friday, March 3, 2006
I'm pretty sure you could set the text length restriction in the callback that you pass into grid.setCellText(). E.g.:

function getText(c, r) {
    var text = data[r][c];
    if (text.length > 140) {
        text = text.substring(0, 140);
    return text;


Or something like that.
Friday, March 3, 2006
Thanks but actually I mean restricting user input to 140 when editing the row, not on initial loading.
Friday, March 3, 2006
Gotcha. I wondered about that after I replied. Apologies.
Friday, March 3, 2006
No not at all, appreciate any response at all.
Friday, March 3, 2006
Are you using an Input template to control the editing? Use something like this to restrict input to 20 characters in the second column:

obj.getCellTemplate(1).getContent("box/text").setAttribute("MAXLENGTH", 20);

Jim Hunter (www.FriendsOfAW.com)
Friday, March 3, 2006
No, I was hoping for a "gridobj.method", but I will try that, thanks.
Monday, March 6, 2006
That doesn't produce any errors but has no effect, any other ideas? Thanks.
Monday, March 6, 2006
It worked for my test, show me your code and we can figure out where the problem is.
Jim Hunter (www.FriendsOfAW.com)
Tuesday, March 7, 2006

I can't seem to get this method to work. I've got a test page, where I create a restricted template on the first column. Can anyone see what the problem is?

Thanks, Helen.

var ukFormat = [
["aaa", "111", "21/02/2005", "", "A"],
["bbb", "22", "01/01/2004", "", "A"],
["bbb", "22", "10/11/2002", "", "B"] ,
["bbb", "22", "31/01/2003", "", "A"],
["bbb", "22", "31/01/2004", "", "B"]

var usFormat = [
["aaa", "111", "02-21-2005", true, "A"],
["bbb", "22", "01-01-2004", false, "A"],
["bbb", "22", "11-10-2002", false, "B"],
["bbb", "22", "01-31-2003", true, "A"],
["bbb", "22", "01-31-2004", true, "B"]

var string = new AW.Formats.String;
var number = new AW.Formats.Number;
var date = new AW.Formats.Date;

var obj = new AW.UI.Grid;

for (var i=0; i<ukFormat.length; i++){
    var combo = new AW.UI.Combo;

    obj.setCellTemplate(combo, 4, i);

obj.setCellTemplate(new AW.Templates.Checkbox, 3);

var template = new AW.Templates.Input
template.getContent("box/text").setAttribute("MAXLENGTH", 5);
obj.setCellTemplate(template, 0);

obj.getCellTemplate(1).getContent("box/text").setAttribute("MAXLENGTH", 5);


obj.setCellFormat([string, number, date]);




for(var i=0; i<obj.getRowCount(); i++){
    obj.getRowTemplate(i).setStyle("background-color", function(){
        return this.getRowProperty("mybackcolor");

obj.defineRowProperty("mybackcolor", function(row){
    if (this.getCellData(4, row) == "A") {
        return "red";

Helen Williamson
Tuesday, May 2, 2006

'maxlength' attribute will not work inside cell template because the cell template is using span with contentEditable=true instead of real <input> box. Maybe the solution in this case would be monitoring entered text with onCellTextChanged event (?).
Alex (ActiveWidgets)
Tuesday, May 2, 2006

This topic is archived.

Back to support forum

Forum search