How to change inputFormat of date item

Hi

I used DD-Mon-YYYY as displayFormat in date item.

{name:"startDate",height:gsmaFormItemHeightVal, type:"date", title:"Effective Date (GMT)", useTextField:true, length:11, titleOrientation:"left",displayFormat: function () {
       return [this.getDate(),this.getShortMonthName(),this.getYear()].join("-")
     }
}

I need to set the same format for inputformat of date item because while validating the date it is giving error.

if(startDate!=null & startDate!=""){
   try{
	  var startDate = form.getItem("startDate").getValue();
	  var startDt = startDate.toSerializeableDate();
   }catch (e) {
	alert(" Invalid Date Format.");
	return false;
   }
}

My requirements are

  1. To set inputFormat=“DD-Mon-YYYY”. There are only 3 chars MDY in api. How we can achieve this?
  2. How we can validate user entered format i.e “DD-Mon-YYYY”?

Thanks in advance.
Vikram

Hi Vikram,

Setting an input format of DMY will automatically handle different separator chars and 2 or 4 digit year values (based on the centuryThreshold property).

Do you really want to use short month names for input? If you require internationalization, it’s going to create significant extra work.

Hi,

We really need to set short month names for input in order to avoid confusion between US and UK date format for end users.
Can you give sample code or example?
One more problem I am facing on mozilla browser that is it is displaying year 2008 as 108. Why so?

Hi
Ok the code to achieve this is using an undocumented feature whereby you can specify a custom “inputFormat” as a parser method name on the Date class. We’ll be adding support for specifying the input format directly as a function in the future but we’ll be sure to update this report when this feature gets added.
Also note that I used “getShortYear” rather than “getYear” to get a reliable short year. The native “getYear” method has different behavior on different browsers.

isc.addProperties(Date, {
   customParser:function (string) {
      var arr = string.split("-");
      // handle 2 digit year - assume century threshold of 2030  
      var year = Math.floor(arr[2]);
      if (year < 1000) {
        var century = year <= 30 ? 2000 : 1900;
        year += century;
      }
      
      // array of short month names:
      var monthNames = Date.getShortMonthNames();
      
      var month = arr[1].substring(0,3);
      month = monthNames.indexOf(month);
      var date = new Date();
      
      date.setYear(year);
      date.setMonth(month);
      date.setDate(arr[0]);
        
      return date;
   }
})
isc.DynamicForm.create({
    ID:"theForm",
    items:[
        {name:"startDate",
         type:"date", title:"Effective Date (GMT)", useTextField:true, length:11,
         titleOrientation:"left",
          displayFormat: function () {
            return [this.getDate(),this.getShortMonthName(),this.getShortYear()].join("-")
          },
          inputFormat:"customParser"
         },
         
         {type:"button", title:"Show date value", click:"isc.warn(theForm.getValue('startDate'))"}
    ]
})

A quick update.
We have now added support for specifying the inputFormat attribute on a DateItem as an explicit function for parsing custom date strings. This will be made public in the next SmartClient release

Thanks
Isomorphic Software

Thanks for your help.
May I know in which version it will be available.

7.0, currently planned for late August. However, you already have working code above.