Reputation: 548
We have a Datefield component with Editable = true
<mx:DateField id="startDate"
width="120"
editable="true"
formatString="MM/DD/YYYY"
selectableRange="{{rangeStart : new Date(2010,0,1), rangeEnd : new Date()}}"
showToday="true"
labelFunction="formatDate"
restrict="[0-9] '\/'" change="startDate_clickHandler(event)"
yearNavigationEnabled="true"
text="{}" tabIndex="15" />
The Calendar has everything we want (able to choose a valid date only after 01/01/2010). Now the issue is that if the user enters (Editable = true) an invalid date or any date < 01/01/2010, how can i validate that and show an alert saying that the date is invalid. Please any help on this would be appreciated.
Thanks
Harish
Upvotes: 0
Views: 8108
Reputation: 1339
You can do it in following way.
<fx:Script>
<![CDATA[
import mx.controls.DateField;
import mx.utils.StringUtil;
private function parseStartDate(valueString:String, inputFormat:String):Date
{
if (StringUtil.trim(valueString) == "")
return null;
var date:Date = DateField.stringToDate(valueString, inputFormat);
if (date == null)
date = new Date(startDate.selectableRange.rangeEnd.time);
else if (date.time < startDate.selectableRange.rangeStart.time)
date = new Date(startDate.selectableRange.rangeStart.time);
else if (date.time > startDate.selectableRange.rangeEnd.time)
date = new Date(startDate.selectableRange.rangeEnd.time);
return date;
}
]]>
</fx:Script>
<mx:DateField id="startDate"
width="120"
selectableRange="{{rangeStart : new Date(2010,0,1), rangeEnd : new Date()}}"
showToday="true"
yearNavigationEnabled="true"
parseFunction="parseStartDate"
editable="true"
formatString="MM/DD/YYYY"
restrict="[0-9/]"/>
Upvotes: 0
Reputation: 10844
Maybe you could try a different aproach after seeing all this great examples
Upvotes: 0
Reputation: 11
The DateField
component has a valueCommit
event that you can listen to. So you can attach a handler to that event and do the validation as required.
Upvotes: 1
Reputation: 16085
The DateField component has a "dataChange" event that you can listen to. So you can attach a handler to that event and do the validation as required.
Upvotes: 1