One of my previous posts on Always showing error tips (validators) presented one way of trying and improve the built-in validation error handling in Flex. It was a nice idea, but as many people have pointed out in the comments there are too many different use cases that causes the error tips to not show up properly.
Below is another alternative approach, and one that I hope is less of a hack.
I've created a class called InputControl which is very similar to the Flex 3 FormItem. It has a label property, and can contain one or more child elements.
What this control does that makes it useful is to listen for when the errorString property changes on an input control (such as a TextInput), and instead of displaying the default Flex error toolTip, it shows that errorString in a label that is always visible. It also immediately clears the input's errorString property so that the default error toolTip is not displayed.
The InputControl class is skinnable, and I've created two different skins. The default one InputControlSkin has the same layout as the FormItem (label on the left) and displays the error string on the right of the input.
The second skin is called InputControlVerticalSkin which displays the label, input, and error message in a vertical layout. This skin is more suited for large inputs like a TextArea.
There are definitely a few issues with this approach:
- longer error messages either don't show up properly or are truncated
- form label alignment is not customizable
Feel free to modify my code to make it work differently. Most properties are hard coded in the skins, and I didn't spend the time to extract them out into styles.
Here it is in action, right click to view source:
Showing posts with label spark. Show all posts
Showing posts with label spark. Show all posts
Thursday, March 24, 2011
Thursday, September 9, 2010
Flex 4 Tree Lines
I've updated my previous blog post on Tree Lines to include a Flex 4/Spark version which uses the MXTreeItemRenderer class.
For more documentation on how to use it see the blog post linked above.
I've also updated the AdvancedDataGrid example to show tree lines in the tree:
For more documentation on how to use it see the blog post linked above.
I've also updated the AdvancedDataGrid example to show tree lines in the tree:
Labels:
AdvancedDataGrid,
Lines,
spark,
Tree
Friday, July 16, 2010
Spark TextArea with Line Numbers
Here is a skin that you can use on the Spark TextArea class to show line numbers down the left side of the text.
The line numbers use the same size font as the TextArea.
It is very simply to use, simply set the skinClass property in mxml like this:
If you want a horizontal scroll bar on the TextArea, then set lineBreak="explicit" and the horizontal scrollbar will appear.
Here is an example of it in action (right click to view source).
It would be very easy to modify this skin to make it resizable by adding a resize handle in the bottom right corner. Look at the source code from my previous blog post on Resizable Controls, specifically the flex.utils.spark.resize.ResizableTextAreaSkin class, it uses a custom skin for the Scroller, which adds the resize handle.
The line numbers use the same size font as the TextArea.
It is very simply to use, simply set the skinClass property in mxml like this:
<s:TextArea skinClass="flex.utils.spark.TextAreaLineNumbersSkin"/>
If you want a horizontal scroll bar on the TextArea, then set lineBreak="explicit" and the horizontal scrollbar will appear.
Here is an example of it in action (right click to view source).
It would be very easy to modify this skin to make it resizable by adding a resize handle in the bottom right corner. Look at the source code from my previous blog post on Resizable Controls, specifically the flex.utils.spark.resize.ResizableTextAreaSkin class, it uses a custom skin for the Scroller, which adds the resize handle.
Labels:
line numbers,
spark,
textarea
Monday, June 28, 2010
Flex 4 Spark Resizable Controls
Please go here for Flex 3 Resizable Containers.
I've created a bunch of skins for many of the common Spark components that allows them to be resized. Each of these skins contains a resizeHandle that when dragged allows the control to be resized. There are two resize handle classes that you can use, the default is called flex.utils.spark.resize.ResizeHandleLines. You can replace every occurrence of that class with flex.utils.spark.resize.ResizeHandleDots if you prefer.
Here are a list of resize skins:
With the exception of the ResizableLabel class, all the others are Skins, and as such can be used very simply by setting the skinClass="flex.utils.spark.resize.___Skin" property to the appropriate skin.
Another option is to create a CSS style for ALL spark.components.Scroller classes to use the flex.utils.spark.resize.ResizableScrollerSkin class like this:
** Note that I've renamed the Flex3 package flex.utils.ui.resize.* to the new Flex4/Spark package name flex.utils.spark.resize.*.
The most used skin is the ResizableScrollerSkin, it is used on TextAreas, Lists, DataGrids, Trees, ComboBoxes, DropDownLists, and anything else that uses a Scroller component. The way it works is to use a skin for the Scroller that adds the resize handle and uses custom HScrollBar and VScrollBar classes which leave room for the resize handle (the simplest way I could think to do it). Each of the resizable skins uses the ResizeManager class to handle the mouse events and resize the appropriate control.
The resizable ComboBox and DropDownList skins are slightly different in that they both save the size of the drop down list since it gets destroyed and re-created each time. It also sets the popUpWidthMatchesAnchorWidth="false" after resizing since the width no longer matches the anchor.
I've also added support for restricting the resize in only the vertical or horizontal direction. There are many ways you can do this, you can either set a style on the resize component:
September 30th, 2010 Update:
I've added a new skin called ResizableDraggableTitleWindowSkin that uses the MoveManager class to allow dragging the TitleWindow around the screen. It also adds a small drag handle in the titlebar too.
The same could be done for other classes (e.g. Panel) by following the same procedure. All that is required is a dragComponent (the component that listens for mouse drag events) and a moveComponent (the component that gets moved - in this case it is the TitleWindow).
Here is an example of most of the skins, view-source enabled.
I've created a bunch of skins for many of the common Spark components that allows them to be resized. Each of these skins contains a resizeHandle that when dragged allows the control to be resized. There are two resize handle classes that you can use, the default is called flex.utils.spark.resize.ResizeHandleLines. You can replace every occurrence of that class with flex.utils.spark.resize.ResizeHandleDots if you prefer.
Here are a list of resize skins:
- ResizableTextAreaSkin (skin for spark.components.TextArea)
- ResizableDropDownListSkin (skin for spark.components.DropDownList)
- ResizableComboBoxSkin (skin for spark.components.ComboBox)
- ResizablePanelSkin (skin for spark.components.Panel)
- ResizableTitleWindowSkin (skin for spark.components.TitleWindow)
- ResizableDraggableTitleWindowSkin (draggable skin for spark.components.TitleWindow)
- ResizableScrollerSkin (skin for spark.components.Scroller)
- ResizableTitledBorderBoxSkin (skin for flex.utils.spark.TitledBorderBox)
- ResizableLabel (extends spark.components.Label, not a skin)
With the exception of the ResizableLabel class, all the others are Skins, and as such can be used very simply by setting the skinClass="flex.utils.spark.resize.___Skin" property to the appropriate skin.
Another option is to create a CSS style for ALL spark.components.Scroller classes to use the flex.utils.spark.resize.ResizableScrollerSkin class like this:
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
@namespace spark "flex.utils.spark.*";
@namespace resize "flex.utils.spark.resize.*";
/* Make all Scroller's use the resizable scroller skin. */
s|Scroller {
skin-class: ClassReference("flex.utils.spark.resize.ResizableScrollerSkin");
}
</fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
@namespace spark "flex.utils.spark.*";
@namespace resize "flex.utils.spark.resize.*";
/* Make all Scroller's use the resizable scroller skin. */
s|Scroller {
skin-class: ClassReference("flex.utils.spark.resize.ResizableScrollerSkin");
}
</fx:Style>
** Note that I've renamed the Flex3 package flex.utils.ui.resize.* to the new Flex4/Spark package name flex.utils.spark.resize.*.
The most used skin is the ResizableScrollerSkin, it is used on TextAreas, Lists, DataGrids, Trees, ComboBoxes, DropDownLists, and anything else that uses a Scroller component. The way it works is to use a skin for the Scroller that adds the resize handle and uses custom HScrollBar and VScrollBar classes which leave room for the resize handle (the simplest way I could think to do it). Each of the resizable skins uses the ResizeManager class to handle the mouse events and resize the appropriate control.
The resizable ComboBox and DropDownList skins are slightly different in that they both save the size of the drop down list since it gets destroyed and re-created each time. It also sets the popUpWidthMatchesAnchorWidth="false" after resizing since the width no longer matches the anchor.
I've also added support for restricting the resize in only the vertical or horizontal direction. There are many ways you can do this, you can either set a style on the resize component:
.resizePanel {
resize-direction: vertical; /* or horizontal */
}
Or you can call a static method on the ResizeManager class:resize-direction: vertical; /* or horizontal */
}
ResizeManager.setResizeDirection(resizePanel, "vertical"); // or "horizontal"
Or if you can access the ResizeManager class (usually stored in the skin class), then you can set the resizeDirection property on the manager like this:resizeManager.resizeDirection = "vertical"; // or "horizontal";
There are constants defined in the ResizeManager class for "vertical", "horizontal", and "both" (default). September 30th, 2010 Update:
I've added a new skin called ResizableDraggableTitleWindowSkin that uses the MoveManager class to allow dragging the TitleWindow around the screen. It also adds a small drag handle in the titlebar too.
The same could be done for other classes (e.g. Panel) by following the same procedure. All that is required is a dragComponent (the component that listens for mouse drag events) and a moveComponent (the component that gets moved - in this case it is the TitleWindow).
Here is an example of most of the skins, view-source enabled.
Labels:
resizable controls,
scroller,
spark
Tuesday, June 1, 2010
TitledBorderBox (Flex 4/Spark)
I've re-written my original TitledBorderBox class (Flex 3) to use Spark/Flex 4 components. It is slightly simpler, and hopefully more lightweight. It extends the SkinnableContainer class, and uses it's own skin (flex.utils.ui.TitledBorderBoxSkin).
Here are the properties on the component:
The way the border is drawn is to simply draw a line over top of the border, but underneath the title that is the same color as the background. If you set borderVisible="false", then it will attempt to find the background color of the parent and use that instead.
Here it is in action (view source enabled, right click):
Here are the properties on the component:
- backgroundAlpha - the background alpha for the box (default: 1)
- backgroundColor - the background color for the box (default: white)
- backgroundVisible - if the background should be shown (default: true)
- borderAlpha - the border alpha for the box (default: 1)
- borderColor - the border color for the box (default: black)
- borderWeight - the thickness of the border (default: 1)
- borderVisible - if the border should be shown (default: true)
- cornerRadius - the corner radius for rounded corners (default: 0)
- dropShadowVisible - if a drop shadow is shown (default: false)
- titleStyleName - the style name for the title label (default "windowStyles")
- title - the title to show in the border
The way the border is drawn is to simply draw a line over top of the border, but underneath the title that is the same color as the background. If you set borderVisible="false", then it will attempt to find the background color of the parent and use that instead.
Here it is in action (view source enabled, right click):
Labels:
spark,
titled border
Subscribe to:
Posts (Atom)