:: Forum >> Version 2 >>

Set input limit for grid row?

More information on this topic is available in the documentation section: /aw.ui.grid/cell-template.html.

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
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(cr) {
    var 
text data[r][c];
    if (
text.length 140) {
        
text text.substring(0140);
    }
    return 
text;
}

grid.setCellText(getText);
 
Or something like that.
Jesse
Friday, March 3, 2006
Thanks but actually I mean restricting user input to 140 when editing the row, not on initial loading.
Rajeem
Friday, March 3, 2006
Gotcha. I wondered about that after I replied. Apologies.
Jesse
Friday, March 3, 2006
No not at all, appreciate any response at all.
Rajeem
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.
Rajeem
Monday, March 6, 2006
That doesn't produce any errors but has no effect, any other ideas? Thanks.
Rajeem
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
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=0i<ukFormat.lengthi++){ 
    var 
combo = new AW.UI.Combo

    
combo.setItemText(["A","B"]); 
    
combo.setItemCount(2); 
    
    
obj.setCellTemplate(combo4i); 
}
    
obj.setCellTemplate(new AW.Templates.Checkbox3); 

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

obj.getCellTemplate(1).getContent("box/text").setAttribute("MAXLENGTH"5);
    
obj.setCellData(usFormat);
obj.setCellText(ukFormat);

obj.setCellFormat([stringnumberdate]); 

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

obj.setCellEditable(true);

obj.setSelectionMode("single-cell");

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

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

obj.setSize(600,300)
document.write(obj);  
Helen Williamson
Tuesday, May 2, 2006
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)
Tuesday, May 2, 2006



This topic is archived.

Back to /aw.ui.grid/cell-template.html

Documentation:

Forum search