开发者

Use same MXML for an Add & Modify Form?

I have a form that is written in MXML that allows a user to create/add a User.

I need to add a form that allows a user to modify SOME but NOT ALL of the fields for this user.

The forms are so similar, I don't want to have to create two separate forms, one for Add and one for 开发者_运维百科Modify.

For example, in the Add form, the user specifies a user id. In the Modify form, the "user id" field is not editable.

I'm wondering how I can initialize the MXML form (i.e. pass in a parameter?) so that it knows whether it is in the Add state or the Modif state.

I know I can't do the following but this is what I would like to do (pseudocode):

if (ADD_FORM) {

mx:TextInput id="txtUserID"

}

else {

mx:Label id="lblUserID"

}


This kind of thing is handled well with states. In Flex 3 you define your states like view, add, and edit. Then you can add the components that are common to all states to the document. Within each state declaration, you can then add the components that are specific to only some states. You can have the edit state dependent on add state since edit is add plus a few more fields.

In Flex 4 this is even easier. You declare your states, and then inline in the single document have all content for all states, with includeIn attributes for which states each element should be included in (or excludeIn).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜