3.0 beta 2

How can I allow only numerics for columns having format AW.Formats.Number

Hi

I have a complex grid in which I am using onCellValidating,onCellEditStarted,onCellValidated, and onCellEditEnded events to also show calculations on footer.

I want only numeric keys to be allowed to be pressed in columns having format as AW.Formats.Number .
I am struck up between the above four events.I have written a function which accepts only numerics in text but I am not able to integrate with AW.
Here is the function :
/***** Disable non character data on numeric columns *****/
function numbersonly(event) {
var unicode=event.charCode? event.charCode : event.keyCode;
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false; //disable key press
}
}
How can I allow only numerics for columns having format AW.Formats.Number?
Please help in this matter.
Thanks
Vikramaditya Garg
Vikramaditya Garg
August 17,
You should use onCellTextChanging instead of keyboard events, otherwise you will not catch copy/paste and drag-and-drop actions -

obj.onCellTextChanging = function(text, column, row){

    if (column == 1) { // column-1 only
        if (text.match(/[^0-9.+-]/)){
            return "error"; // prevent non-digits
        }
    }
}
Alex (ActiveWidgets)
August 21,
Alex,

I tried "obj.onCellTextChanging", but its fired only when the data in the cell is loading (I have a XML based table) and is not fired while editing the values in the cell.

While editing a cell the events that are fired in that order -
onCellEditStarted, onCellValidating, onCellValidated, onCellEditEnded.

Like Vikramaditya Garg, i also have the requirement of not allowing the user to type in non-neumeric keys in a neumeric column.

Please suggest a solution.

thanks
Raj Nair
August 21,
Hi

I also agree with Raj.

We have added a workaround

obj.onCellValidating = function(text, column, row){
//Max range an integer is allowed in the grid : 2147483647
var value = Number(text);
if (!(value > -1) || !(value < 2147483648)) {
window.status = "Invalid value : " + text + ", should be in the range 0 to 2147483647";
return true;
} else {
window.status ="";
}
}

This shows error messages on status bar.We can also use label for this purpose.
Still we are waiting for the better approach.

Thanks
Vikramaditya Garg
Vikramaditya Garg
August 22,
Sorry, I don't understand - can you please explain what is wrong with using onCellTextChanging event?
Alex (ActiveWidgets)
August 24,
Hi Alex,

I tried with onCellTextChanging event,I have seen that this event is fired only when data in the grid cell is loading.When I edit a Cell, this event is not called.

I am trying to block characters in Numeric columns except dot.This is necessary as per our business requirements.

How can I prevent characters from being entered in Numeric Cells?

Thanks
Vikramaditya Garg
Vikramaditya Garg
August 28,
Are you sure that the event does not fire? I cannot reproduce this. Can you try again the complete example below -

var obj = new AW.UI.Grid;
obj.setCellData(function(col, row){return col + "." + row});
obj.setHeaderText("header");
obj.setColumnCount(10);
obj.setRowCount(10);
obj.setCellEditable(true);
document.write(obj);

obj.onCellTextChanging = function(text, column, row){
    if (text.match(/[^0-9.+-]/)){
        return "error"; // prevent non-digits
    }
}
Alex (ActiveWidgets)
August 29,
I put an alert in the code. The alert will show the value when the data is loaded to the grid for the first time. The alert is not shown while the cell is being edited.

obj.onCellTextChanging = function(text, column, row){ 
    alert(text); 
    if (text.match(/[^0-9.+-]/)){ 
        return "error"; // prevent non-digits 
    }
}
Raj Nair
August 29,
Normally onCellTextChanging event should fire on each text change during the editing - when typing, pasting text from the clipboard or drag-and-drop operation.

Do you have this problem with the clean 2.0.1 code? In which browser/OS? Does it happen on one machine or several different ones?
Alex (ActiveWidgets)
August 29,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.