3.2.0

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.
Rajeem
March 3,
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;
}

grid.setCellText(getText);


Or something like that.
Jesse
March 3,
Thanks but actually I mean restricting user input to 140 when editing the row, not on initial loading.
Rajeem
March 3,
Gotcha. I wondered about that after I replied. Apologies.
Jesse
March 3,
No not at all, appreciate any response at all.
Rajeem
March 3,
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)
March 3,
No, I was hoping for a "gridobj.method", but I will try that, thanks.
Rajeem
March 6,
That doesn't produce any errors but has no effect, any other ideas? Thanks.
Rajeem
March 6,
It worked for my test, show me your code and we can figure out where the problem is.
Jim Hunter (www.FriendsOfAW.com)
March 7,
Hi,

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; 

    combo.setItemText(["A","B"]); 
    combo.setItemCount(2); 
    
    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.setCellData(usFormat);
obj.setCellText(ukFormat);

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

obj.setColumnCount(ukFormat[0].length); 
obj.setRowCount(ukFormat.length); 

obj.setCellEditable(true);

obj.setSelectionMode("single-cell");

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";
    }
});

obj.setSize(600,300)
document.write(obj);
Helen Williamson
May 2,
Helen,

'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)
May 2,

This topic is archived.

See also:


Back to support forum