Setting selectable ranges in the Flex DateField control
The following example shows the various usages of the selectableRange property for the DateField control in Flex.
The first usage only sets the rangeStart value within the selectableRange property Object. This allows you to have a calendar which allows the user to only select dates after the specified date. Similarly, the second usage only sets the rangeEnd value within the selectableRange property Object, which only allows the user to select dates before the specified date. Finally, the third usage sets both the rangeStart and rangeEnd values within the selectableRange property Object which allows you to limit the selectable dates to a certain range.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2007/12/17/setting-selectable-ranges-in-the-flex-datefield-control/ --> <mx:Application name="DateField_selectableRange_test" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"> <mx:Form> <mx:FormItem label="rangeStart only:"> <mx:DateField id="dateField1" showToday="false" selectableRange="{{rangeStart:new Date()}}" /> </mx:FormItem> <mx:FormItem label="rangeEnd only:"> <mx:DateField id="dateField2" showToday="false" selectableRange="{{rangeEnd:new Date()}}" /> </mx:FormItem> <mx:FormItem label="rangeStart/rangeEnd:"> <mx:DateField id="dateField3" showToday="false" selectableRange="{{rangeStart:new Date(2007, 11, 3), rangeEnd:new Date(2007,11,28)}}" /> </mx:FormItem> </mx:Form> </mx:Application>
View source is enabled in the following example.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
12 Responses to Setting selectable ranges in the Flex DateField control
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Can this be set where the second datefield will only accept dates higher than the date selected in the first one? Does it support bindable data in that object you pass to the component?
Nice! very thanx
peterd – It’s helpfull, thanks
Is there a way to dynamically assign the rangeStart and rangeEnd? For instance, I’m using the DateField as the itemEditor in a DataGridColumn, and I need to be able to assign a selectableRange that isn’t hard coded.
Okay, I figured out how to assign a selectableRange that isn’t hard coded to a DateField that is used as an itemRenderer. The key piece I was missing was to use outerDocument to reference the object that would be used as the range:
<mx:Script> <![CDATA[ private var dateRange:Object = new Object(); dateRange["rangeStart"] = startDate; dateRange["rangeEnd"] = endDate; ]]> </mx:Script> ... <mx:DataGrid> <mx:columns> <mx:DataGridColumn> <mx:itemRenderer> <mx:Component> <mx:DateField selectableRange="{outerDocument.dateRange}" /> </mx:Component> </mx:itemRenderer> </mx:DataGridColumn> </mx:columns> </mx:DataGrid>nice one. what if i want to display for one month time stamp(taking the latest date(coming from database) as end date ). it should be dynamic.
Thanks Peter. Great post.
It’s helpfull.
Thanks Peter
Thanks!!!!!! It’s very helpfull!
This is an excellent example. However I notice one situation that is not covered here that I recently had to hanle in my code.
What if you want users to be only able to select dates within the last x amount of days in my case 60. You can’t set the start date to a specific date sense the start date will increase by 1 each day. In that case the following code will work
selectableRange=”{{rangeStart:new Date(new Date().getTime() – 5184000000), rangeEnd:new Date()}}”
notice the use of the getTime method in the start date means that you have to know how many miliseconds have passed in the past x days
x * 24(60(60(1000)))
where x is the number of days you are looking for
@Michael Liscio,
Great tip, thanks! Also, you can probably do something similar to the following:
Peter
Hi,
If i want to enable only working days in calendars, then how i do that?
Thanks