Pet peeve: Calendar fields and data validation

So far so good, but I’m getting stuck editing the format of the field.
The sample solution has the DATETIME field format set to “converter”.
When I try to set this I get the following error.
In fact, I get the same error if I try to edit the field in the sample.
This is with Servoy 5.1.2
Not sure what I’m doing wrong.

Hi Antonio,

You want the converter on the table column, not on the form field (else you have to use the onDataChange event).
Go to the table under your database server node. Select the column and go to the validation tab.
Here you select the servoy.globalMethodValidator. Now some events appear and you can add your global methods to that.
I believe this will make the ‘converter’ option (which is not part of the value list options) show up in the formatting window.

Hope this helps.

Perfect!
Thanks for the speedy response. I’d set up the conversion tab; didn’t realise we have to do the validation tab too.

I’ve got the converter working, can enter text in to the field date_of_birth, parse it and display it on the form.
Now I’d like to perform a calculation on the field. It should be stored as a date, correct? However, calculations that reference the field now see it as text, not as a date.

e.g a function with this code now breaks,

var vAgeDays = (application.getTimeStamp()-date_of_birth)/86400000

because date_of_birth evaluates as the string 26/05/2009 instead of Tues May 26 21:06:59 EST 2010

Is this expected behaviour? How do methods reference the date value stored in the field?

for column converters where you say input (db type) is a date and output is text then everything (records/calcs) will see it as that text value.

so if you get in through javascript it will also be that text value and if you set it it also goes through the converter…

I guess what you want is only have that conversion on the form ui level. This is currently not supported please make a case describing this.

Thanks Johan, that makes sense. I can see that there is case for making this behaviour specific to a form - display as a date field on some forms, and as a converter on others, and treating it as a datetime for calcs in methods.

So that I’m clear, what’s the advantage of storing it in a date field if functionally it’s text - compared to making it a text field. What circumstances would benefit from this approach?

You can hook up the date.js conversions at the form level instead of the table level, if you want. Just bind a text_field to a form variable and set the date value from it on the field events, it’s just a little more work on the UI setup level, especially if you have a lot of date fields or the field appears on a lot of different forms.

antonio:
Thanks Johan, that makes sense. I can see that there is case for making this behaviour specific to a form - display as a date field on some forms, and as a converter on others, and treating it as a datetime for calcs in methods.

So that I’m clear, what’s the advantage of storing it in a date field if functionally it’s text - compared to making it a text field. What circumstances would benefit from this approach?

if you need to search or sort on that column in the database, it is handier that it is a date column in the database.
But if your converter makes it a Text column for servoy, then typing into it could support more things (like “now” or +1, which is today +1 day)

agiletortoise:
You can hook up the date.js conversions at the form level instead of the table level, if you want. Just bind a text_field to a form variable and set the date value from it on the field events, it’s just a little more work on the UI setup level, especially if you have a lot of date fields or the field appears on a lot of different forms.

Great tip, thanks!
My next challenge - in Smartclient I put a button next to the textfield to simulate the popup calendar.
The wiki states that application.showCalendar() isn’t supported in webclient, (though it does pop up as a non-modal when testing in developer with Safari?)
What’s the best way to show a date chooser for this text field that works in both SC and WC?

Hi Tony,

Where in the wiki does it say that? I searched for showCalendar and only got 2 hits (5.0 and 5.1) and none of these entries said anything about not working in webclient.
Of course you could always create your own datepicker like I did (see viewtopic.php?t=14174) which works in both SC and WC.
I will release this module soon (excl. the masking, like shown below) which uses Greg’s datejs module.

[attachment=0]mod_datepicker.png[/attachment]

Here.
http://wiki.servoy.com/display/public/D … y+overview
in the box titled Not Supported.
You have to leave off the () to find it in a search

ROCLASI:
Of course you could always create your own datepicker like I did (see viewtopic.php?t=14174) which works in both SC and WC.
I will release this module soon (excl. the masking, like shown below) which uses Greg’s datejs module.

The JSDatePicker module is now released on ServoyForge.