Hi all, I have Read/Write grid in which there are numeric columns with datatype D20.2 When I am entering a long value like 01234567890123456789 it gets converted into ********************** and it is getting updated as 0 in database table.Is there any way to restrict user from entering values which are not consistent with the datatype of the column associated with Grid.
Thanks in advance.This message has been edited. Last edited by: Kerry,
According to the documentation D formats will store and display the 15 most signifcant digits. P format will go to 31 significant digits. I format will go to 10 digits and F format is something like 7 significant digits.
You should be able to find this in the Describing Data manual for your release.
In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
September 28, 2011, 12:17 PM
Maintain Wizard
You can use this technique to create a mask to limit the number of characters entered into the Active-X Grid in Maintain. You want to set up the mask when the user clicks or tabs into the cell.
Setting limit using QuickSetMask Function prevents invalid entries, overflows, or truncations. Recommended use for OnCellChange and OnLClicked Events.
// OnCellChange Event (if TAB or ENTER to next cell) Form1.Grid1.UseMaskedEdit(1); // enable mask editing Form1.Grid1.QuickSetMask (newCol, newRow, "CCCC");
// OnLClicked Event (if left mouse clicking to next cell) Form1.Grid1.UseMaskedEdit(1); // enable mask editing Form1.Grid1.QuickSetMask (col, row, " CCCC");
Where: 0 - Digit (0 through 9), entry required; plus and minus signs not allowed. 9 - Digit or space (entry optional; plus and minus signs not allowed) A - Letter or Digit (Entry required) a - Letter or Digit (Entry optional) L - Letter (A through Z, entry required) ? - Letter (A through Z, entry optional) C - Any character or a space (Entry optional) & - Any character or a space (Entry required)
Mark
September 30, 2011, 05:13 AM
Shankar
Hi, I have a field in table column with datatype NUMBER(8,4) . Suppose user want to enter value 111.11 and I have used Form1.Grid1.QuickSetMask (12, row, "CCCC.CCCC"); to restrict user.Now when user tries to enter the value it will be taken as 111..11 which is not proper and the time of updation,it is updated as 111.0000 in database table.So,I want that when user enters ' .' before '.' in QuickSetMask function, it should not allow anymore '.' and restricts user to enter only 4 digits after decimal point.How to handle this? Please help.
The only thing that the Mask function can do here is limit the number of characters. If you use:
function OnGrid1_OnCellChange ( int col, long row, int newCol, long newRow) { Form1.Grid1.UseMaskedEdit(1); // enable mask editing Form1.Grid1.QuickSetMask (newCol, newRow, "CCCCCCCC"); }
function OnGrid1_OnLClicked ( int col, long row, boolean updn, boolean processed) { Form1.Grid1.UseMaskedEdit(1); // enable mask editing Form1.Grid1.QuickSetMask (newCol, newRow, "CCCCCCCC"); }
You limit the input to 8. Do not use a decimal in the mask. Let the user enter that themselves. You can then check the value of the input either using JavaScript here, or in the Maintain to determine if the value is incorrect before updating the database.
You can use the OnCellChanged event to get the value and make sure it is not greater than 999.9999.
Mark
October 01, 2011, 06:59 AM
Alan B
The simplest way to achieve this type of validation in JavaScript is to use regular expressions. Use an onchange event on the field and check against a reg ex:
<html>
<head>
<title>Check Reg Exp</title>
<script>
function checkNumber() {
var regexp=/(?!^0*$)(?!^0*\.0*$)^\d{1,10}(\.\d{1,4})?$/;
// numerics and decimal point
// 10 before decimal point, change to requirement
// . 1 decimal point
// 4 after decimal point, change to requirement
if (document.getElementById("number").value.search(regexp)==-1)
alert("Please enter a valid number inside form")
}
</script>
</head>
<body>
<input type="text" name="number" id="number" onchange="checkNumber()">
</body>
</html>
Alan. WF 7.705/8.007
October 03, 2011, 04:04 AM
Shankar
Hi Mark, When iam trying to capture value entered by user by using below piece of code it is giving me previous value present in the cell.
function OnGrid1_OnCellChanged ( long col, long row, string text) {
var c1 = evest_hold.Grid1.GetCurrentColumn;
var r1 = evest_hold.Grid1.GetCurrentRow;
evest_hold.Grid1.GetCell(c1,r1);
var StrCellGet = evest_hold.Grid1.CellGetText;
alert (StrCellGet);
}
e.g suppose there is value 1 present in a cell and user is trying to change it to 2, the CellGetText function returns 1 which is not required.I need to capture the value 2 and determine whether it is not greater than 999.9999 before updating database.How can I capture the new value inserted?