Flex Repeater

Hello every one,
please use cairngorm.swc file

my question is.
select the number of passengers and when you click on submit button i am going to show the data like passenger DateofBirth field and age feild in the second page.

when i change the date feild to the passenger date of birth i need to populate the age feild with the age of passenger (this should be calculated according to the date selected in date feild) and that should show in years(like if age is one year and two months it should show as 1.2)

and when i click the submit button in second page i need to check whether all the feilds are entered in the repeater.

can anybody help me in this.

Thanks in advance

RepTest.txt
first.txt
second.txt
last.txt
AppModelLocator.txt
srujanmiryalaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSoftware engineerCommented:
>> if age is one year and two months it should show as 1.2
???
one year and 1 month = 1.1
one year and 10 months = 1.10 also?

Since 2 months = 2/12 or 1/6 or 0.16666 year shouldn't that be 1.1666666?
0
srujanmiryalaAuthor Commented:
Hello ZZynx,
Sorry for the late reply.i was waiting for the confirmation how the age should be displayed.
it should be disaplayed in months(i.e one year and 1 month = 13).
0
zzynxSoftware engineerCommented:
In second.mxml there's

    for(var i:int=0;i<modellocator.numberofPassengers;i++) {

while numberofPassengers is undefined in AppModelLocator.
Same for

     passinfArrayColl

and

     LAST
0
INTRODUCING: WatchGuard's New MFA Solution

WatchGuard is proud to announce the launch of AuthPoint, a powerful, yet simple, Cloud-based MFA service designed to eliminate the vulnerabilities that put your data, systems, and users at risk.

srujanmiryalaAuthor Commented:
package
{
      import com.adobe.cairngorm.model.IModelLocator;
      
      import mx.collections.ArrayCollection;
            
      [Bindable]
      public class AppModelLocator implements IModelLocator
      {
            public static var instance:AppModelLocator;
            public function AppModelLocator(enforcer:SingletonEnforcer)
            {
                  if (enforcer == null)
                  {
                        throw new Error("You can only have one modal locator");
                  }
            }
            public static function getinstance():AppModelLocator
            {
                  if (instance == null)
                  {
                        instance = new AppModelLocator(new SingletonEnforcer);
                  }
                  
                  return instance;
            }
            
            // Define Variablea
            public var workflowState:uint = 0;
            
            // Number of passengers
                                          public var numberofPassengers:int;
            public var passinfArrayColl:ArrayCollection;
            
                        
            // Define Constants
            public static const FIRST:uint = 0;
            public static const SECOND:uint = 1;
            public static const LAST:uint = 2;
            

      }
}
class SingletonEnforcer{}
0
srujanmiryalaAuthor Commented:
hey zzynx:

Did you find any solution for this i have kept the model locator code in previous comment
0
zzynxSoftware engineerCommented:
This is my second.mxml
(I hope that is the only thing I changed - it's a while ago I did the changes)
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"  width="100%" height="100%">
	<mx:Script>
		<![CDATA[
			import mx.events.CalendarLayoutChangeEvent;
			import mx.collections.ArrayCollection;
			import mx.controls.DateField;
			
			[Bindable]
			public var modellocator:AppModelLocator = AppModelLocator.getinstance();
			
			
			public function updateRepeater():void
			{
				var passArr:Array = new Array();
				for(var i:int=0;i<modellocator.numberofPassengers;i++){
					var o:Object = new Object();
					o.age = new Number(0);
					o.birthday = new Date();
					passArr.push(o);
				}
				passInformation.dataProvider = passArr; 
			}
			
			private function proceedHandler(event:MouseEvent):void{
				modellocator.passinfArrayColl = new ArrayCollection();
				for(var j:int=0 ; j<modellocator.numberofPassengers; j++ ){
					var item:Object = new Object;
					item.age = AGE[j].text;
					item.dob = DOB[j].text;
					modellocator.passinfArrayColl.addItem(item);
				}
				modellocator.workflowState = AppModelLocator.LAST;
				
			}
			
			private function onDateChange(event:CalendarLayoutChangeEvent):void {
			    var df:DateField = event.currentTarget as DateField;

				var date:Date = df.selectedDate;
				var now:Date = new Date();
				
				var day:Number = date.date;
				var month:Number = date.month;
				var year:Number = date.fullYear; 
				var ageInMonths:Number = -1;
				
				while (date.getTime() < now.getTime()) {
					ageInMonths++;
					if (month==11) {
						year = year+1;
						month = 0;
					} else {
						month++;
					}
					date = new Date(year, month, day);
				}
				trace("Age in months = ", ageInMonths);
				df.getRepeaterItem().age = ageInMonths;
				df.getRepeaterItem().birthday = df.selectedDate;
				passInformation.dataProvider.refresh();
			}
			
			
		]]>
	</mx:Script>
	
	<mx:VBox width="100%" top="10">
	<mx:VBox width="100%" verticalGap="2" horizontalGap="2">
		<mx:Canvas width="100%">
			<mx:Label text="AGE" fontWeight="bold" x="135"/>
			<mx:Label text="DOB" fontWeight="bold" x="206"/>
		</mx:Canvas>
	</mx:VBox>
	<mx:VBox id="passInf" width="100%" verticalGap="2" horizontalGap="2">
		<mx:Repeater id="passInformation"   >
			<mx:Form >
				<mx:FormItem label="Passenger Details:" required="true" direction="horizontal">
					<mx:TextInput id="AGE" editable="false" text="{passInformation.currentItem.age}" width="39"/>
					<mx:DateField id="DOB" yearNavigationEnabled="true" selectedDate="{passInformation.currentItem.birthday}" change="onDateChange(event)"/>					
				</mx:FormItem>
			</mx:Form>
		</mx:Repeater>
	</mx:VBox>
	
	</mx:VBox>
	<mx:Button label="Proceed" click="proceedHandler(event)" x="163.5" y="243"/>
</mx:Canvas>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
srujanmiryalaAuthor Commented:
Hey You are Excellent
Thank you very much.
Onemore Question after clicking the proceed button and before navigating to last page i need to check whether all the feild in the repeater are entered or not. how to do this.
0
zzynxSoftware engineerCommented:
thanx 4 axxepting

>> Onemore Question after clicking the proceed button and before navigating to last page i need to check whether all the feild in the repeater are entered or not. how to do this.
http://livedocs.adobe.com/flex/3/html/help.html?content=validators_2.html
http://blog.flexexamples.com/2007/08/13/validating-flex-forms-using-the-validator-classes/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.