Welcome Guest Search | Active Topics | Sign In | Register

Datetime validator Options
UweD
Posted: Monday, February 2, 2009 10:50:30 AM
Rank: Advanced Member
Groups: Member

Joined: 8/11/2008
Posts: 37
Is there a possibility to check for a valid DateTime in a grid?
eo_support
Posted: Monday, February 2, 2009 11:24:10 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

I do not think you can validate on the spot. What you can do is to handle the Grid's ClientSideOnCellSelected:

http://doc.essentialobjects.com/library/1/eo.web.grid.clientsideoncellselected.aspx

You can use a global variable to keep track of the previous selected cell. You can then check whether the previous cell is a cell that you would like to validate when user moves to a new cell. If it is, you would validate the cell value and if necessary, changes it back to a valid value. You will need these two functions:

http://doc.essentialobjects.com/library/1/jsdoc.public.gridcell.getvalue.aspx
http://doc.essentialobjects.com/library/1/jsdoc.public.gridcell.setvalue.aspx

Hope this helps.

Thanks!
eo_support
Posted: Wednesday, February 18, 2009 5:01:49 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We have posted a new build that extended ClientSideBeginEdit and ClientSideEndEdit from CustomColumn only to all GridColumns. A new sample has also been added to Grid -> Features -> Client Side Validation to demonstrate this feature. You can use this new feature to perform validations when user leaves the cell.

Note you will be able to validate/change the cell value inside your handler, but the handler does not give you the ability to keep the cell in edit mode. We did not provide such support through ClientSideEndEdit because our experience indicates most users find unable to leave edit mode to be annoying. If you do wish to keep user in edit mode, you can call the following function to put the cell back to edit mode:

http://doc.essentialobjects.com/library/1/jsdoc.public.grid.editcell.aspx

The code will be something like this:

Code: JavaScript
function endedit_handler(cell, newValue)
{
    //Check whether your new value is invalid using
    //whatever logic
    if (new_value_is_invalid(newValue))
    {
        //You can display a message at here indicating 
        //that the user has entered an invalid value
 
        window.setTimeout(
            function()
            {
                //Get the grid object
                var grid = cell.getGrid();

                //Put the cell back to edit mode
                grid.editCell(cell.getItemIndex(), cell.getColIndex);
            }, 10);
    }
}


Note the code uses setTimeout to call editCell instead of calling it directly. This is necessary to allow the cell to finish the current flow first and then enter edit mode again.

Please see your private message for the download location of the new build. Hope this helps.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.