Question
· May 4, 2018

Zen - Problem with dateText component (format and separator attributes)


When working with the dateText component in a Zen Application and setting the parameters "format:DMY" and "separtator:/" I cannot save the  right date to the database.

In short, I have a structure similar to :

Class View.A Extends  %ZEN.Component.page
{


XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
{

...

 <dataController id="a-controller" modelClass="MVC.A"/>

 <dynaForm id="a-form"  controllerId="a-controller" onsubmit="return zenPage.saveForm();"/>

}

}
Class MVC.A Extends %ZEN.DataModel.ObjectDataModel
{

Property DOB As %Date  (ZENATTRS = "id:DOB|format:DMY|separator:/, ZENCONTROL = "dateText") ;


... other methods


Method %OnStoreModel(pSource As Modelo.Pedido) As %Status
{
  Set pSource.DOB = ..DOB
  Quit $$$OK
}

}
Class Model.A Extends %Persistent
{

Property DOB As %Date;

}

When I don't use the attributes "format" and "separator", then it's saved normally. However, with them , the date saved is  "1840-12-31".

I've seen the below post about a similar subject, but it was a long time ago. Is it possible that the bug still exists in version "2015.2.1.705.1" (mine)?

https://groups.google.com/forum/#!topic/intersystems-zen/VLCqAlXumjI

I wonder if someone could point the solution to me.

Discussion (2)0
Log in or sign up to continue
USER>w $zv
Cache for Windows (x86-32) 2015.2 (Build 664_3U) Wed Aug 12 2015 12:29:34 EDT

The date is saved to the database correctly.

Class dc.A Extends %Persistent
{
Property DOB As %Date;
}

Class dc.MVC.A Extends %ZEN.DataModel.ObjectDataModel
{

Property DOB As %Date(ZENATTRS "id:DOB|format:DMY|separator:/"ZENCONTROL "dateText");

Method %OnNewSource(Output pSC As %Status = {$$$OK}) As %RegisteredObject
{
  ##class(dc.A).%New()
}

Method %OnOpenSource(
  pID As %String,
  pConcurrency As %Integer -1,
  Output pSC As %Status = {$$$OK}) As %RegisteredObject
{
  ##class(dc.A).%OpenId(pID,pConcurrency,.pSC)
}

Method %OnSaveSource(pSource As dc.AAs %Status
{
  pSource.%Save()
}

ClassMethod %OnDeleteSource(pID As %StringAs %Status
{
  ##class(dc.A).%DeleteId(pID)
}

Method %OnLoadModel(pSource As dc.AAs %Status
{
  ..DOB pSource.DOB
  q $$$OK
}

Method %OnStoreModel(pSource As dc.AAs %Status
{
  pSource.DOB = ..DOB
  q $$$OK
}

}

Class dc.test Extends %ZEN.Component.page
{

XData Contents [ XMLNamespace "http://www.intersystems.com/zen" ]
{
  <page xmlns="http://www.intersystems.com/zen">
    <dataController id="a-controller" modelClass="dc.MVC.A" modelId=""/>
    <dynaForm id="a-form"  controllerId="a-controller"/>
    <button caption="Save" onclick="zen('a-form').save();" />
  </page>
}

}