So there will be an array on your document
called role and you could loop through it and grab the name and selected state.
Var selectedRoles:Array = [];
For (var i:Number=0; I < role.length;
i++)
{
If (role[i].selected)
{
selectedRoles.push([role[i].label);
}
}
But yes, it’s better to store these
things in a Model or just update the user directly:
<mx:CheckBox id=”role”
label=”{rolesList.currentItem}” selected=”{user.hasRole(rolesList.currentItem)}”
valueCommitted=”user.setRole(event.target.getRepeaterItem(),
event.target.selected)” />
Matt
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Richard Rodseth
Sent: Wednesday, November 02, 2005
4:40 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: Flex
1.5 - n checkboxes
No, my requirements are
simple. An "Edit User" panel with checkboxes for all the roles the
user has.
I have the check boxes rendering as follows
<mx:Repeater
id="rolesList" dataProvider="{allroles}">
<mx:CheckBox
id="role" label="{rolesList.currentItem}"
selected="{user.hasRole(rolesList.currentItem)}" />
</mx:Repeater>
Now, I need to submit the form, and call user.setRoles() with an array of the
the checked roles. Right now there roles are just strings, but they should
probably be Role objects.
Presumably I will need a submit handler that iterates over the checkboxes
looking at their selected state and building the array of checked ones. I don't
know how to do that yet, but I'm sure I can figure it out.
It would be nifty if there was a more automatic way to do this.
Thanks,
Richard
On 11/2/05, Brendan
Meutzner <[EMAIL PROTECTED]>
wrote:
Hi Richard,
I recently completed a project in which we had to
dynamically build
form selection elements based on different control
types (eg.
checkboxes, radio buttons, etc...). The data
model we worked with
provided us with the string name of the control
type to use, and the
appropriate data structure to populate the control
type(s). Solution
I came up with was to (as you mention you might
have to do) create the
form elements using actionscript, more
specifically the createChild
method. I created a custom instance of each
control type, and added
some additional properties to it, the most
important being the data
property it needed to affect. Inside the
custom control, I had my
change event directly modify the data property
that was passed in.
Because the reference was passed in, this
essentially "bound" that
change to the data model it came from.
Problem solved.
Your requirements may be slightly different as it
sounds like you
already know what type of control you need to
render. In this case, I
would imagine you could use a repeater tag and
have it's children be
the custom "check box" you're creating,
and pass in the object
property reference that needs to be changed.
Hope this helps you...
Brendan
--- In flexcoders@yahoogroups.com,
Richard Rodseth <[EMAIL PROTECTED]> wrote:
>
> Yes, as I mentioned, I am using the repeater tag. But the
data
provider for
> it is the list of all possible roles. I'm interested in the
process of
> mapping the checked items to an array of objects (strings or
value
objects).
> I'm guessing there's no way around using Actionscipt to
populate the
form
> from the model and vice versa.
>
> - Richard
>
> On 11/2/05, Matt Chotin <[EMAIL PROTECTED]> wrote:
> >
> > Check out the Repeater tag.
> >
> > ------------------------------
> >
> > *From:* flexcoders@yahoogroups.com
[mailto:flexcoders@yahoogroups.com] *On
> > Behalf Of *Richard Rodseth
> > *Sent:* Wednesday, November 02, 2005 9:07 AM
> > *To:* flexcoders@yahoogroups.com
> > *Subject:* [flexcoders] Flex 1.5 - n checkboxes
> >
> > Is there a slick way to bind a variable number of
checkboxes to
an array
> > of value objects in a data model?
> >
> > Example: user has an array of roles. Display a list of
checkboxes
> > I see how to use repeaters to render the checkboxes,
but I'm
unclear on
> > the best way to capture the user selections.
> >
> > Thanks
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
> >
> >
> > ------------------------------
> > YAHOO! GROUPS LINKS
> >
> >
> > - Visit your group
"flexcoders<http://groups.yahoo.com/group/flexcoders>"
> > on the web.
> > - To unsubscribe from this
group, send an email to:
> >
[EMAIL PROTECTED]< [EMAIL PROTECTED]>
> > - Your use of
Yahoo! Groups is subject to the Yahoo! Terms of
> > Service <http://docs.yahoo.com/info/terms/>.
> >
> >
> > ------------------------------
> >
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
YAHOO! GROUPS LINKS