Flex 3: Hiding elements created by repeater - flex3

I have a repeater that creates a custom component named "Block." I need to make it so that when the user clicks a button, all of the blocks created by the repeater have their visible field set to false (and then true when the button is clicked again).
Here's some of the code I have right now:
<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0">
<components:block height="24"
width="100%" id="thisBlock" visible="true" horizontalScrollPolicy="off"
oneDay="{oneDay}"
/>
</mx:Repeater>
Here's the button the user will click to show/hide the blocks:
<mx:Button id="showHideButton" label="Show Project" x="{addBlock.x + addBlock.width + 2}" click="showProjectSwitch();" />
Here's the function showProjectSwitch():
public function showProjectSwitch():void {
if (showHideButton.label == "Hide Project")
{
showHideButton.label = "Show Project";
indPositions.visible = false;
thisProject.height = 65;
}
else
{
showHideButton.label = "Hide Project";
indPositions.visible = true;
thisProject.height = projectHeight ;
}
}
I tried setting projectRP.visible="true/false", but it didn't work :(
I also tried wrapping a canvas around the repeater, but when I did that... the repeater only ran once despite the fact I have the startingIndex="0" and the count="16". I then removed the canvas tags and the repeater ran the correct number of times.
Anybody able to help me out?

The easiest way to achieve what you want is just to use databinding, same as you did for the "oneDay" value.
<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0">
<components:block height="24"
width="100%" id="thisBlock" visible="true" horizontalScrollPolicy="off"
oneDay="{oneDay}"
visible="{showBlocks}"
/>
</mx:Repeater>
<mx:Boolean id="showBlocks" />
[Edit for additional clarity]
To change the visibility of the blocks, you need to set the value of showBlocks, like so:
showBlocks = true;
or
showBlocks = false;

Here's how i solved it... since the variable name of "thisBlock" is declared every time a block is made, all that information gets stored in an array. After learning this, i was able to create a for each loop in a function that was called when the show/hide button was pressed... the for each loop goes something like this:
for (var I:int = 0; i < dataprovidername.length; i++)
thisBlock[i].visible = true/flase;
Hope that can help somebody else out in the future.

Related

Styling Apache DataGrid in flex 4.15

I would like to know, how I can change the background color of an datagrid item!
I use external CSS and with flex 4.6 I use:
s|ItemRenderer
{
contentBackgroundColor: #FF0000;
}
But I have to upgrade to apache flex 4.15 and it doesn't work anymore... I can't find which component I suppose to style. In the documentation I can't find the list of styles available T_T.
If you have a link or answer thx!
In the documentation of adobe Flex it's said:
An item renderer is associated with a column of the DataGrid control. The item renderer then controls the appearance of each cell in the column. However, each item renderer has access to the data item for an entire row of the DataGrid control. Use the data property of the item renderer to access the data item.
Try to accomplish that by using ItemRenderer for all your columns you can do that in MXML manner or by mixing MXL with Action script code like applying the style for a known column:
<mx:DataGrid x="29" y="303" width="694" height="190" dataProvider="{testData.book}" variableRowHeight="true">
<mx:columns>
<mx:DataGridColumn headerText="Title" dataField="title">
<mx:itemRenderer>
<mx:Component>
<mx:HBox paddingLeft="2">
<mx:Script>
<![CDATA[
override public function set data( value:Object ) : void {
super.data = value;
var today:Number = (new Date()).time;
var pubDate:Number = Date.parse(data.date);
if( pubDate > today ) setStyle("backgroundColor",0xff99ff);
else setStyle("backgroundColor",0xffffff);
}
]]>
</mx:Script>
<mx:Image source="{data.image}" width="50" height="50" scaleContent="true" />
<mx:Text width="100%" text="{data.title}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
or in separated action script class by excluding the content of the script tag mentioned to action script class extending your column's type and overriding the set data method like:
public class CheckBoxHeaderRenderer extends CheckBox
{
override public function set data(value:Object):void
{
_data = value as CheckBoxHeaderColumn;
selected = _data.selected;
//type your condition here using the property of your dataField
if(data.property=="value"){
this.styleName="yourClassCSSName"
}
}
and your class CSS will be like:
.yourClassCSSName{
contentBackgroundColor: #FF0000;
}
for more:
Understanding Flex itemRenderers
Creating item renderers and item editors for the Spark DataGrid control

Get the picker value when another button is pushed

This is my index.xml
index.xml
<Window>
<Picker id="picker" type="Ti.UI.PICKER_TYPE_DATE" selectionIndicator="true" top="100"></Picker>
<Button id="button" onClick="clickSelDateBut" title="決定"
top="350" width="100" height="50" />
</Window>
I would like to get the picker value when button is clicked
For now my source code is here.
index.js
$.picker.addEventListener('change',function(e){
selDay = e.value.getDate();
selMonth = e.value.getMonth() + 1;
selYear = e.value.getFullYear();
});// keep the data when 'change' event happens..
function clickSelDateBut(e){
//using selDay selMonth selYear here
}
However,it's not cool.
I think I should pick up the data from picker when the button is clicked.
How can I make it?
If u want some button to be clicked and get its value then do something like this
$.button.addEventListener('click',function(e){
selDay = picker.value.getDate();
selMonth = picker.value.getMonth() + 1;
selYear = picker.value.getFullYear(); });
})

Telerik Rad Button Dyanamically check

Have been unable to dynamically check a Telerik Rad Button control from the code behind in vb.net code. I have used things like chk_TypeEmployee.Checked = True with no result.
<telerik:RadButton ID="chk_TypeEmployee" runat="server" ToggleType="Radio" ButtonType="StandardButton" GroupName="StandardButton" Text="Employee"></telerik:RadButton>
<telerik:RadButton ID="chk_TypeAgency" runat="server" ToggleType="Radio" ButtonType="StandardButton" GroupName="StandardButton" Text="Agency"></telerik:RadButton>
You need to use ToggleStates:
<telerik:RadButton ID="chk_Type" runat="server" ToggleType="Radio" ButtonType="StandardButton" GroupName="StandardButton" Checked="true">
<ToggleStates>
<telerik:RadButtonToggleState Value="Employee" Text="Employee" PrimaryIconCssClass="rbToggleRadioChecked" />
<telerik:RadButtonToggleState Value="Agency" Text="Agency" PrimaryIconCssClass="rbToggleRadio" />
</ToggleStates>
</telerik:RadButton>
To set dynamicaly the button to "Agency" state, assuming it is the second ToggleState for the button:
chk_Type.ToggleStates[0].Selected = false;
chk_Type.ToggleStates[1].Selected = true;
Could be rewritten cleaner this way:
string DBValue = "Agency";
foreach (RadButtonToggleState state in chk_Type.ToggleStates)
{
state.Selected = state.Value.Equals(DBValue);
}
And to retrieve the selected value, use the chk_Type.SelectedToggleState.Value.
Note: The RadButton's property Checked must be set to true. And at least 1 of your toggle states should be Selected, else the first toggle state would be selected by default. In order to use more than 2 toggle states, please read about ToggleType="Custom".
Read more about Telerik's Toggle Buttons.

FindControl in DataList Edit Mode

As a new .net/C# web begginner, I always get tripped up when I try to use FindControl. Blam -flat on my face. Here is my current FindControl problem:
I have an .aspx page and Form, then ajax updatePanel, inside it there is my DataList (DataList1) that has an EditItemTemplate: that has the following:
<EditItemTemplate>
<asp:Label ID="thumbnailUploadLabel" runat="server" text="Upload a new thumbnail image:"/><br />
<asp:FileUpload ID="thumbnailImageUpload" runat="server" />
<asp:Button ID="thunbnailImageUploadButton" runat="server" Text="Upload Now" OnClick="thumbnailUpload"/><br />
</EditItemTemplate>
In my C# code behind I have the OnClick code for the fileUpload object:
protected void thumbnailUpload(object s, EventArgs e)
{
if (thumbnailImageUpload.HasFile)
{
//get name of the file & upload
string imageName = thumbnailImageUpload.FileName;
thumbnailImageUpload.SaveAs(MapPath("../../images/merch_sm/" + imageName));
//let'em know that it worked (or didn't)
thumbnailUploadLabel.Text = "Image " + imageName + "has been uploaded.";
}
else
{
thumbnailUploadLabel.Text = "Please choose a thumbnail image to upload.";
}
So of course I'm getting "Object reference not set to an instance of an object" for the FileUpload and the Label.
What is the correct syntax to find these controls, before dealing with them in the OnClick event?
The only way Ive used FindControl is something like:
label thumbnailUploadLabel = DataList1.FindControl("thumbnailUploadLabel") as Label;
But of course this is throwing the "Object reference not set to an instance of an object" error. Any help is very much appreciated.
(I've also seen the 'recursive' code out there that is supposed to make using FindControl easier. Ha! I'm so green at C# that I don't even know how to incorporate those into my project.)
Thanks to all for taking a look at this.
I know this is a hell lot late but i was looking for questions to answer....you must have figured it by now but still
if you add these lines in your code
protected void thumbnailUpload(object sender, EventArgs e)
{
FileUpload thumbnailImageUpload =(FileUpload)DataList1.Items[DataList1.EditItemIndex].FindControl("thumbnailImageUpload");
Label thumbnailUploadLabel = (Label)DataList1.Items[DataList1.EditItemIndex].FindControl("thumbnailUploadLabel");
if (thumbnailImageUpload.HasFile)
{
//Your code here
}
else
{
thumbnailUploadLabel.Text = "Please choose a thumbnail image to upload.";
}
}
this will find the appropriate control for the row you are editing...
also keep your Datalist out of the UPdate Panel beacuse Update Panels are not compatible with FileUpload. if you do the code will run but it will always show thumbnailImageUpload.HasFile as False.

MouseEvent.MOUSE_DOWN over mx:TextInput

I'm working on a simple flex / AIR application with just a mx.TextInput control and some button. I'm not using the system chrome.
less or more the mxml is this:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="495" height="316" creationComplete="init()">
<mx:TitleWindow width="481" height="84" layout="absolute" horizontalCenter="0" showCloseButton="false" id="win" top="10">
<mx:Label text="blahhh" id="label1" left="0" top="0"/>
<mx:TextInput id="textinput1" left="155" top="0" right="5" editable="true" />
<mx:Label text="expand" right="36" bottom="0" click="toggleState()"/>
<mx:Label text="exit" click="stage.nativeWindow.close()" right="0" bottom="0"/>
</mx:TitleWindow>
</mx:Application>
To make the window draggable i've added a MouseEvent.MOUSE_DOWN listener to the TitleWIndow:
win.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void { stage.nativeWindow.startMove();});
The problem now is that the inner textinput control seems to inherit the eventlistner, so you can type text, but you can't select it (Cause holding down the mouse trigger the NativeWindow.move() function).
Am I missing something ? I want the window to be draggable only when i mousedown on the TitleWindow, not on other controls..
You should check the target attribute of the event object, like this:
win.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
if (e.target == win)
stage.nativeWindow.startMove();
});
Otherwise you also catch mouseDown events bubbling up from inner elements such as the TextInput.