MXML: combobox width is larger than parent width - apache-flex

I have a combobox with a width set to 100%. However, when one of its elements is larger, the combobox grows larger aswell, creating scrollbars and other uglyness in my app!
How do I keep the combobox contained within its parent?
NB it's OK if the list that drops down is larger as long as the closed combobox stays smaller.
Sample:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
<!-- I'm using a Canvas instead of a VBox because the VBox spaces the elements too far appart -->
<mx:HBox id="tagsHBox" width="{formsHBox.width - 16}" x="8" y="8">
<!-- This label should align with the labels in the left form -->
<mx:Label text="Tags" id="tabLabel" width="{titleTxt.x + 4}" textAlign="right" />
<!-- This textbox should spread accross both forms, that's why it's in a seperate HBox -->
<mx:TextInput height="20" width="100%" />
</mx:HBox>
<mx:HBox id="formsHBox" x="8" y="{8 + tagsHBox.height}" width="{this.width-16}">
<mx:Form id="leftForm" width="50%">
<!-- Personal details -->
<mx:FormHeading label="Personal Details" width="100%" />
<mx:FormItem label="First name" width="100%">
<mx:TextInput text="{person.firstName}" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Last name" width="100%">
<mx:TextInput text="{person.lastName}" width="100%"/>
</mx:FormItem>
<!-- And 15 more formItems :) -->
</mx:Form>
<mx:Form id="rightForm" width="50%">
<!-- Address -->
<mx:FormHeading label="Address" width="100%" />
<mx:FormItem label="Street" width="100%">
<mx:TextInput text="{person.address.street}" width="100%"/>
</mx:FormItem>
<mx:FormItem label="City" width="100%">
<mx:TextInput text="{person.address.city}" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Country" width="100%">
<!-- This combobox right here is the troublemaker. There's a
country named 'South Georgia and the South Sandwich
Islands' consising of a few small islands in the southern
pacific and a name which is too long for my innocent
unsuspecting combobox -->
<form:ComboBox id="countryCombo" height="20" width="100%"
dataProvider="{model.systemDataModel.countries}" />
</mx:FormItem>
<!-- And 15 more formItems :) -->
</mx:Form>
</mx:HBox>
</mx:Canvas>

You might be able to use minWidth instead. Set it to zero or some other low value. I know it works with containers like HBox and VBox to make them stop growing larger than their parent container, so it might work with ComboBox too. Basically, what happens is that minWidth="0" overrides the measuredMinWidth, which is a value that the parent container normally respects as the minimum possible size, and it may be bigger than the container's own bounds.

I had the same issue and I solve it easily. I had a country comboBox and a state comboBox components and dynamically filled with country names and the other with states related... I had two forms inside an HBox to show "two columns like" forms and inside the right side form there was a formItem and inside the formItem the comboBox. The problem was when I gave the comboBox its dataProvider then scrollBars appeared and it was very disgusting...
The solution: I show you just the right form because it was the problem (autoLayout="false" in Form and minWidth="0" in ComboBox definition)
<mx:Form autoLayout="false" verticalGap="12">
<mx:FormItem label="Country" required="false" width="100%" direction="vertical">
<mx:ComboBox id="countryComboBox" minWidth="0" width="100%" labelField="#name"/>
</mx:FormItem>
<mx:FormItem label="State" required="false" width="100%" direction="vertical">
<mx:ComboBox id="stateComboBox" minWidth="0" width="100%" labelField="#name"/>
</mx:FormItem>
</mx:Form>

You can use the maxWidth attribute with an absolute size (in pixels) however part of the combobox items ( which are larger then the combobox ) will be cropped .
from adobe :
combobox default size :
Wide enough to accommodate the longest entry in the drop-down list in the display area of the main control, plus the drop-down button. When the drop-down list is not visible, the default height is based on the label text size.

Related

Getting a custom view to scroll in Flex 4.5 Mobile

I'm trying to create a custom view (one that is not 100% listview, for example), mix and matching images and labels.
One issue is that when the label overflows greater than the screen height, the rest just gets off. I had assumed scrolling or touch-drag scrolling would be automatically enabled? How do you enable the touch-drag scrolling that happens naturally in list view?
I wrap all the visual elements of my View inside a Scroller - this will solve that problem
<s:Scroller id="scroller" left="10" right="10" top="10" bottom="10" >
<s:VGroup paddingTop="3" paddingLeft="5" paddingRight="5" paddingBottom="3" horizontalAlign="center">
<s:HGroup horizontalAlign="right" width="100%">
<s:Image scaleMode="letterbox" source="#Embed('images/small_background.GIF')"/>
</s:HGroup>
<s:TextInput id="txtUsername" prompt="Enter user name..." fontFamily="Arial"/>
<s:TextInput id="txtPassword" prompt="Enter password..." fontFamily="Arial"
displayAsPassword="true" />
<s:Button />
<s:Button />
</s:VGroup>
</s:Scroller>

In flex, how to declare a control to take all available width

In Flex 4.0, I have a project with a videodisplay, and below it some controls that I've created (play/pause button, HSlider for showing progress, some volume controls...)
The problem arises when the flash is displayed in a window that is too small to fit all controls at their desired width. What I see is that some controls are pushed to the right, out of sight. (Maybe it's because they are in a custom container that acts as a window, but that's needed functionality).
I want to designate the HSlider as having flexible width, so when the user creates a small window, the items in the control bar are still visible, and the HSlider is compressed enough to make that happen...
Cheers!
Edit: the code for my window (it's the VBox that I would like to have variable-sized):
<ns1:CollapsableTitleWindow x="294" y="36.65" backgroundColor="#000000" width="436" height="373" id="wnd" title="test" allowClose="false">
<mx:VideoDisplay width="100%" height="100%" id="vd" autoPlay="false" volume="1"/>
<mx:ControlBar id="ctrlbarLiveVideo1" width="100%">
<mx:Button width="30" height="22" id="btnPlay" click="{doplay();}" icon="{imgPlayButton}"/>
<mx:VBox verticalGap="1" horizontalAlign="right">
<mx:HSlider id="slider" width="100%" invertThumbDirection="true" maximum="{vd.totalTime}" minimum="0" tickInterval="{vd.totalTime/10}" value="{Number(vd.playheadTime)}" />
<mx:Label text="{sec2hms(Number(vd.playheadTime))} / {sec2hms(Number(slider.maximum))}"/>
</mx:VBox>
<mx:HBox id="box" horizontalGap="1" verticalAlign="middle">
<mx:Label id="lblVolume" text = "{String(Math.round(vd.volume*100))+'%'}"/>
<mx:Button label="-" id="btnless" width="34" height="22" verticalGap="0" labelPlacement="top" labelVerticalOffset="0" click = "{vd.volume -= 0.10}"/>
<mx:Button label="+" id="btnmore" width="34" height="22" verticalGap="0" labelPlacement="top" labelVerticalOffset="0" click = "{vd.volume += 0.10}"/>
</mx:HBox>
</mx:ControlBar>
</ns1:CollapsableTitleWindow>
Produces this screenshot:
Apparently the answer was: set the minWidth of the HSlider explicitly to 0:
<mx:HSlider minWidth="0" id="slider" width="100%" ... />
And also make the VBox width="100%": (thanks to code90)
<mx:VBox width="100%" verticalGap="1" horizontalAlign="right">

laying out formitems in flex

for some reason my code is not having the desired effect of having labels to the left of the textinput fields*(like in nearly all normal scenarios with forms). The labels are appearing above the textinput fields. I would also like to make some of them read only. Any advice much appreciated
Basically what i have is text sitting above the textbox instead of alongside it to the left.
Here is my code:
<mx:VBox width="100%" height="100%">
<mx:HBox>
<mx:FormItem textAlign="left" <mx:Label text="TEST" textAlign="left" fontSize="14" fontWeight="bold"/>
<mx:TextInput enabled="true" textAlign="right"/> </mx:FormItem>
Use the label field of the formitem.
<mx:FormItem textAlign="left" label="TEST" fontSize="14" fontWeight="bold"/>
<mx:TextInput enabled="true" textAlign="right">
</mx:FormItem>
If you want read-only, then you can put editable="true|false" in the TextInput.

flex - laying out form items both vertically and horizontally

I am trying to create a simple form in flex (flash builder 4). I placed a form container and FormItems inside. The form items are for example standard "customer" fields such as First, Last, Address, City, State, Zip.
By default it lays the fields out vertically and makes the field labels right justified, which looks nice.
However, I would like some of the fields to be horizontal - for example, something like this:
First __________ Last ___________
Address _____________________
City ___________ St ___ Zip ____
I tried putting the first/last in an HGroup container, but that does not quite work - I loose the right justification of the labels, looks something like this:
First __________ Last ___________
Address _____________________
City ___________ St ___ Zip ____
This is an example of how I am trying to make first/last horizonal, but it will not be right justified with referral - however city and referral are right justified together:
<mx:Form x="0" y="307" width="100%">
<s:HGroup>
<mx:FormItem label="First"> <s:TextInput/></mx:FormItem>
<mx:FormItem label="Last"><s:TextInput/></mx:FormItem>
</s:HGroup>
<mx:FormItem label="Referral"><s:TextInput/></mx:FormItem><mx:FormItem label="City">
<s:TextInput/>
</mx:FormItem>
</mx:Form>
It's almost like I need a sort of table layout with colSpan ability, or ?
This custom component looked promising but does not appear to work in fb4 at least http://cookbooks.adobe.com/post_Multi_Column_Form_Layout-9644.html
Also, are there any good books / sites / etc that discuss user interface design / form design and similar in Flex that I can browse?
The only way I found to accomplish that is by using an mx:Grid.
Mainly because the mx:GridItems have a colSpan or rowSpan attribute. Furthermore I use empty mx:FormItems in stead of Labels, because you can use the required attribute to show a (*) for required fields.
Here's an example:
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<mx:Form width="100%" height="100%">
<mx:Grid width="100%" height="100%">
<mx:GridRow>
<mx:GridItem>
<mx:FormItem label="First" required="true"/>
</mx:GridItem>
<mx:GridItem>
<s:TextInput/>
</mx:GridItem>
<mx:GridItem>
<mx:FormItem label="Last"/>
</mx:GridItem>
<mx:GridItem>
<s:TextInput/>
</mx:GridItem>
</mx:GridRow>
<mx:GridRow>
<mx:GridItem width="100%" height="100%">
<mx:FormItem label="Last"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%" colSpan="3">
<s:TextInput width="100%"/>
</mx:GridItem>
</mx:GridRow>
</mx:Grid>
</mx:Form>
</s:Group>
Hope this helps,
Koen
The answer is to just use CSS. Create a label style in CSS that specifies textAlign to 'left'. Then take that label style and apply it to the labelStyleName property on the formItem.
Here is a full app that demonstrates the fix:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
.labelStyleName {
textAlign:left;
}
</fx:Style>
<mx:Form x="0" y="307" width="100%">
<s:HGroup>
<mx:FormItem label="First" horizontalAlign="left" labelStyleName="labelStyleName">
<s:TextInput/>
</mx:FormItem>
<mx:FormItem label="Last" horizontalAlign="left" labelStyleName="labelStyleName">
<s:TextInput/>
</mx:FormItem>
</s:HGroup>
<mx:FormItem label="Referral" horizontalAlign="left" labelStyleName="labelStyleName">
<s:TextInput/>
</mx:FormItem>
<mx:FormItem label="City" horizontalAlign="left" labelStyleName="labelStyleName">
<s:TextInput/>
</mx:FormItem>
</mx:Form>
</s:Application>
If you want more specific lining up of the input items; you may have to specify a labelWidth value.
You should avoid using multiple HGroups if you want columns aligned, it can easily break when you downsize browser window so that it can't show all the content at once. The content overflowing logic will then break the alignment most likely. Use mx:Grid instead as an ultimate solution or s:Form for very simple cases.

Issues displaying the Background in VBox while using WindowShader

I am using a WindowShader in my website. every thing is working fine. but for somereason i am unable to display any background for my "home_feeds" VBox. If i add components on it, i can see them. But they backgound is not working. Even if i remove every thing from the Canvas(with home_feeds) i still dont see any background. But if i remove the comments from my mx:List.. i can see the background.
my code is given below
<mx:VBox right="35" paddingRight="10" verticalAlign="top" horizontalAlign="right">
<containers:WindowShade id="shade" opened="false" openIcon="{null}" closeIcon="{null}" paddingTop="0"
headerLocation="bottom" visible="true">
<containers:headerRenderer>
<mx:Component>
<flexlib:CanvasButton width="100%" height="20" skin="mx.skins.ProgrammaticSkin">
<mx:Script>
<![CDATA[
import flexlib.containers.WindowShade;
]]>
</mx:Script>
<mx:Box width="100%" horizontalAlign="center">
<degrafa:Surface width="80">
<degrafa:GeometryGroup>
<geometry:EllipticalArc closureType="pie"
arc="180" startAngle="-180" width="80" height="35" y="-18">
<geometry:fill>
<paint:GradientFill angle="90">
<paint:GradientStop color="#920000" />
<paint:GradientStop color="#D31F1F" />
</paint:GradientFill>
</geometry:fill>
</geometry:EllipticalArc>
<geometry:Polygon>
<geometry:data>40,5 35,13 45,13</geometry:data>
<geometry:stroke>
<paint:SolidStroke color="#333333" alpha="{WindowShade(parent).opened ? 1 : 0}" weight="1" />
</geometry:stroke>
<geometry:fill>
<paint:SolidFill color="#ffffff" alpha="{WindowShade(parent).opened ? 1 : 0}" />
</geometry:fill>
</geometry:Polygon>
<geometry:Polygon>
<geometry:data>40,13 35,5 45,5</geometry:data>
<geometry:stroke>
<paint:SolidStroke color="#333333" alpha="{WindowShade(parent).opened ? 0 : 1}" weight="1" />
</geometry:stroke>
<geometry:fill>
<paint:SolidFill color="#ffffff" alpha="{WindowShade(parent).opened ? 0 : 1}" />
</geometry:fill>
</geometry:Polygon>
</degrafa:GeometryGroup>
</degrafa:Surface>
</mx:Box>
</flexlib:CanvasButton>
</mx:Component>
</containers:headerRenderer>
<mx:Canvas horizontalScrollPolicy="off" width="200" height="350" >
<!--mx:List id="home_feeds" height="100%" width="100%" itemRenderer="file_manager.list_item_template" doubleClickEnabled="true" /-->
<mx:VBox id="home_feeds"
width="100%"
backgroundAlpha="0.1"
left="10"
right="10">
</mx:VBox>
</mx:Canvas>
<containers:filters>
<mx:DropShadowFilter alpha=".3" angle="90" />
</containers:filters>
</containers:WindowShade>
</mx:VBox>
Kindly let me know what am i doing wrong here.... And how can i fix it. I want to use the VBox there.
Regards
Zeeshan
The size of a VBox without an explicit value for width would be zero if it doesn't have any children in it. Add some children (a Label for example) to see the background color. Increase background alpha from 0.1 to 0.5 or something to see it clearly.
If you mention explicit values for width and height (instead of percentages), you can see the background color even if it doesn't have any children.
set backgroundColor="#00ff00" (green) for the home_feeds VBox to differentiate VBox's background color from its parent's color.

Resources