Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    accepting user entered date in date component

    Hi,
    I am using user defined short display format.
    This works when i select some date using datepicker, it shows date in required user format.

    But when i get value of some date field to make some server query by
    var valueDate = grid.getEditedRecord(rowNum).valueDate;

    i get value Date in Thu Jan 31 2008 00:00:00 GMT+0800 (Malay Peninsula Standard Time) which is default toString format.
    But for invalid dates entered by user then this returns user entered value.

    My requirement is to get same value as it is being displayed.
    ie. even if user entered invalid date / valid date directly or using date picker i need user value as it is. In other words i want to use date field just to get date time picker. want to avoid any parsing internally.

    How can i do that ?


    Code:
    <% if(GenUtil.FMT_DDMMYYYY.toUpperCase().equals(userPrefDateFormat))
            { %>
            	Date.setInputFormat("DMY");
             <%} 
    else if(GenUtil.FMT_MMDDYYYY.toUpperCase().equals(userPrefDateFormat))
            { %>
            	Date.setInputFormat("MDY");         
            <% } %>
    
    Date.setShortDisplayFormat(userPrefDateFormatter);
    
    function userPrefDateFormatter () 
    {
    	
    	if("<%= GenUtil.FMT_DDMMYYYY.toUpperCase() %>" == userPrefDateFormat)
            {
            
            	var selDate = this.getDate() + "";
            	var selMonth = this.getMonth() +1 + "";
            	
            	var date = ("0"+selDate).substring(selDate.length - 1,selDate.length + 1);
            	
            	var month = ("0"+selMonth).substring(selMonth.length - 1,selMonth.length + 1);
            	
            	return date + "." + month + "." + this.getFullYear();
            }
            else if("<%= GenUtil.FMT_MMDDYYYY.toUpperCase() %>" == userPrefDateFormat)
            {
            
            	
    		var selDate = this.getDate() + "";
            	var selMonth = this.getMonth() +1 + "";
            	
            	var date = ("0"+selDate).substring(selDate.length - 1,selDate.length + 1);
            	
            	var month = ("0"+selMonth).substring(selMonth.length - 1,selMonth.length + 1);
            	
            	return month + "." + date + "." + this.getFullYear();
            }
          
          
    }

    #2
    Actually this call:

    Code:
    var valueDate = grid.getEditedRecord(rowNum).valueDate;
    Will give you a JavaScript Date object. If you are logging or alert()ing this object you'll see the result of Date.toString(). But you can call methods on it (including your own formatter) to get it in any format you want.

    By the way your formatter code is extremely inefficient. If you use it in a grid with lots of visible rows, it's going to be the dominant performance factor in some browsers - try searching the web for some tuning tips.

    Comment

    Working...
    X