84395

How to send an array of Flex checkboxes to a mysql server?

Question:

I am using FB for PHP 4.5, ZendAMF, and I read that I do not need to use HTTPService for what I want to do.

Table structure:

people: {pID, pName} departments: {deptID, deptName} people_departments: {pID, deptName}

I have a slightly complex flex script, People.mxml. In the PersonAdd state, I have a form which will be used to send data to the mysql server. In that form , I have a repeater that will create a checkbox for every department in my database. When I click the Add button, I want to insert data into the people and people_departments tables.

Repeater code:

<mx:HBox> <mx:Repeater id="checkBoxRepeater" dataProvider="{getDepartmentsResult.lastResult}"> <s:CheckBox id="deptCB" label="{checkBoxRepeater.currentItem.deptName}"/> </mx:Repeater> </mx:HBox>

In my peopleService.php file, I will have the function createPerson(People $item,$deptArray) and inside that function, I will execute two SQL queries. One query will insert data into the People table and the other one will insert data into people_departments, with people_departments.pID = ID of newly inserted person.

As you can see, in the Repeater code above, the checkbox as the attribute label. However, when I send the dept_Array (of type ArrayCollection) to the server, the former needs to contain deptIDs. How can I do so?

This is how I create the dept_Array in People.mxml to send to the server:

protected function button_clickHandler(event:MouseEvent):void { var dept_array:Array=[]; var idx:int; var getDepts_array:ArrayCollection=new ArrayCollection; getDepts_array=getDepartmentsResult.lastResult as ArrayCollection; var len:int=getDepts_array.length; for (idx=0; idx < len; idx++) { if (deptCB[idx].selected) { dept_array.push(deptCB[idx].label); //here I need to be able to push the ID of selected department. } } }

[Edit] I am using an s:Checkbox and I do not have the data property. mx:Checkbox does but I cannot use the mx:Checkbox component in my project.

I would appreciate any help. Also, is there is a better way to do this?

Answer1:

try to bind the selected property with your getDepartmentsResult to save the selected state :

<mx:HBox> <mx:Repeater id="checkBoxRepeater" dataProvider="{getDepartmentsResult.lastResult}"> <s:CheckBox id="deptCB" label="{checkBoxRepeater.currentItem.deptName}" selected={checkBoxRepeater.currentItem.deptSelected}/> </mx:Repeater> </mx:HBox>

After that iterate on your collection to get the selected department:

protected function button_clickHandler(event:MouseEvent):void { var dept_array:Array=[]; var idx:int; var getDepts_array:ArrayCollection=new ArrayCollection; getDepts_array=getDepartmentsResult.lastResult as ArrayCollection; var len:int=getDepts_array.length; for each (var dept:Object in getDepts_array) { // ... } if (dept.selected) { dept_array.push(dept.label); //here I need to be able to push the ID of selected department. }

} }

Answer2:

I solved the problem by using the attribute automationName to send the ID related to the itemName displayed as the checkbox label.

Note that the data attribute does not exist for the spark checkbox. If you use the mx:Checkbox, you have data, and you can use it to send the ID linked to your item in question.

<mx:Tile id="myTile"> <mx:Repeater id="checkBoxRepeater" dataProvider="{getItemsResult.lastResult}" startingIndex="0"> <s:CheckBox label="{checkBoxRepeater.currentItem.myItemName}" id="checkbox" automationName="{String(checkBoxRepeater.currentItem.myItemID)}" change="checkbox_changeHandler(event,event.currentTarget.repeaterIndex)"/>^ </mx:Repeater> </mx:Tile>

I know that this may not be the best solution, but I am apparently the first person to do this commonplace task, and this worked for me.

And then, the send the array of the IDs of the selected checkboxes, I use the following code, defined in my submitBtn_clickHandler function:

var items_array:Array=[]; var idx:int; var getitems_array:ArrayCollection=new ArrayCollection; getitems_array=getItemsResult.lastResult as ArrayCollection; var len:int=getitems_array.length; for (idx=0; idx < len; idx++) { var element:CheckBox=myTile.getElementAt(idx) as CheckBox; if (element.selected) { items_array.push(element.automationName); } }

I then pass items_array as an additional parameter to my ItemService.createItem function.

Recommend

  • Android ViewPager skip page animation
  • Passing a custom model into a Umbraco Partial View and getting object casting error
  • Use jquery to target classes that are added dynamically?
  • How to set a boolean flag to collapse/expand a row with ng-repeat
  • How to get minimal jQuery slideshow to slide properly?
  • c# Set value to a DataRow automatically
  • 'NSInvalidArgumentException', reason: '-[AVPlayerItem duration]: unrecognized selecto
  • Add business days to the new date in jquery
  • How to send an array of Flex checkboxes to a mysql server?
  • ViewPager : Navigating Back to Parent Fragment From Child Fragment Closes The Application
  • Play video in reverse using AVPlayer and Swift on IOS 9
  • Outlook Add-on to Add Text to Mail Body
  • How to find control with in repeater on button click event and repeater is placed with in gridview i
  • Using AVPlayer for streaming is slow
  • Flex: Special-casing an item in a list or menu?
  • Testng - How to run cleanup code after a test method is run for all data providers?
  • Flex Horizontal List
  • Selenium with Java and TestNG - Test login with Excel DataSheet
  • Leaking NSAutoreleasePool
  • How to access nested Json Data in AmCharts
  • How to run specified step in SoapUI according testcase result
  • Unable to Parse Multiple IN1 Segment in HL7 using HAPI TERSER
  • Error handling in WPF PasswordBox
  • Pulling Columns from Excel
  • yii2 sorting in related model
  • How to resolve permission denied maybe missing internet permission?
  • ApplePay PKPaymentAuthorizationViewController always shows processing
  • xcode don't localize specific strings
  • Swift: Switch statement fallthrough behavior
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo