问题
I would like to know how to make a DateField control with a watermark. I want to set the prompt/watermark text from MXML like this one:
<mx:DateField id="id_date" propmt="Select date" />
回答1:
Use this
<mx:DateField id="df" text="Select Date" focusIn="df.text=''" />
OR
Refer This Blog for custom datefield component
WaterMarkDateField
回答2:
Its Quite Simple by using the creation complete handler
<mx:DateField id="sample" creationComplete="sample_creationCompleteHandler(event)"/>
set the sample text like this
protected function sample_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
sample.text = "Select Date";
}
Try this..
回答3:
I have done like following way. Don't know it's correct way or not. But, it's working for me.
<mx:DateField id="dateIdentify" editable="true" selectedDate="new Date()" formatString="MM-DD-YYYY" color="#505050" focusOut="if(dateIdentify.text == ''){dateIdentify.text='MM-DD-YYYY'}" focusIn="if(dateIdentify.text == '' || dateIdentify.text == 'MM-DD-YYYY'){dateIdentify.text='';}" text="MM-DD-YYYY"/>
Hope it helps someone.
来源:https://stackoverflow.com/questions/8005602/how-can-i-watermark-a-datefield-control-in-flex-4