Get value of editbox of type date/time

382 views Asked by At

I try to get the value of an editbox of type Date/Time. If I test it with

getComponent("dateField").value 

or

 getComponent("dateField").getSubmittedValue();

and print the output to the console. It always returns "null" if the field is empty or the field does not contain a valide date. Because of this I can't differ between invalide input and empty input.

Is there a way to get the information if the field is empty?

1

There are 1 answers

1
Paul Stephen Withers On BEST ANSWER

It depends on the refresh phase you're testing.

getValue() will always return blank, because only content that can be converted to the underlying data type will be passed to it. Even if you disable validation, converter checks still run, because serious errors will occur if you try to put "this is not a date" into a Date/Time.

getSubmittedValue() will always be null if you're checking in Invoke Application or Render Response phases. That's because during the Update Model Values phase, the submittedValue property is passed to the value property and the submittedValue property nulled.

If you're checking in a validator, the text value entered by the user has not yet been checked against validation rules (validation) or that it can be converted to the right data type (conversion), so getValue() will return the value stored last time round and getSubmittedValue() will give the string value (e.g. "this is not a date").

So the answer is you should be able tell whether the field is empty in a validator, but bear in mind custom validators only run if you also have a required validator.