Avatar

Not applicable

Hello all,

I'm having some trouble with the formattedValue property.

So far, i have used it successfully in order to validate the date format when the user exits a date field in my form. The solution was quite easy to find, and although i didn't understand fully how it worked it copied/pasted it in my javascript code.

For those interested, here's the deal:

if(this.rawValue == this.formattedValue){
    xfa.host.messageBox("Please use the calendar or enter a date in the format DD/MM/YYYY (e.g. 05/03/2011)");
    xfa.host.setFocus(this.somExpression);
    this.rawValue = "";
}

As i understood it, when the user inputs something in a date field the "formattedValue" of the field is the input formatted with the format defined in the object property, eg DD/MM/YYYY in my case. If it cannot be formatted, then the "formattedValue" is equal to the "rawValue" and thus there is some kind of problem that is handled by the "if" condition.

I also have time fields in my form. In the object properties, i have set the format to "HH:MM:SS".

Naturally, i thought I could use the same trick to force the user to input a correct time format. But there's some difficulties: it works except when the user actually inputs a time that is already correctly formatted. So, if the user inputs "12:05:05" for example, the formattedValue is equal to the rawValue. Thus the if condition is true and that should not be the case...

of course, i could write a few lines to split the string, parse into int, then check the values (>0 and <24 for hours, etc.), but i'd like to have something a little bit cleaner...

With the date, everything works fine, because the rawValue, for some reason, is automatically formatted with YYYY-MM-DD. Thus the formattedValue is never the same as the rawValue when the date is correct...

Isn't there a way to find a simple solution? maybe have a time default format like "hh:mm:ss:ms" (with milliseconds) ?

thank you.