actionscript 3 - Flex/Spark: How much logic in view? How to clear a TextField as a reaction to a user click or an event? -


When using Flex with SPARC, I have a message in which to enter your message, a TextInput and button send . TextInput

  • "" <
  • should be set to " which
  • Should also be set to "" event = "myOtherEvent"
< When a response to button

  • should be enabled only text input 's text.length & gt; 0 < / Code>

At first I thought it was very clean to leave the binding to the text entered in TextInput to do anything in my model And to give it the logic to see / disable the viewing of the button.

I still think this is a very good way except for the fact that it There is not a complete solution because it is unclear as a response to receiving TextInput.text event = "myOtherEvent" .

that partial The solution is MXML:

   Input id = "chatText" width = "100%" height = "32" /> & Lt; S: button label = "send" enabled = "{chatText.text.length> gt;" click = '{model.send (chattext.text); ChatText.text = ""} '/ & gt;  

If it was not for the need to respond to my event, how do you feel about that solution?

There are some arguments in the button , but just basic settings and checking I know that separating the argument and presentation is a good idea, but I thought it was a good balance Was there.

A Complete Solution I think that may be:

  • chattext.text and one in my model
  • And in the method set for that property, I Dispatches (New Event ("UpdateButton")
  • A function in the same model class from that event This function will return enabled = "{model.thatFunction ()}" button's .function chatTextStringPropertyInModel.length & gt; 0 and thus (some By jumping through hoops) it will see that to send When a text is available, send- button is enabled.
  • You can set model.send (chatText.text) chatTextStringPropertyInModel = " " and after that the property is bound to chattext.text as two ways, change will also appear in the UI. / Li>

My question:

  1. How logic is correct in the view?
  2. How do I solve it? What is the most beautiful and maintenance?

Maybe I'm confused but I'm not your solution Switch to a problem you see pre your event

<> & lt; Fx: Script & gt; Requires adding an event handler. & Lt ;! [Disable text and disable on private text on [CDATA [//] other events. MyOtherEvent (Event: Event): Zero {chatText.text = ""; }] & Gt; & Lt; / Fx: script & gt; & Lt; S: TextInput id = "chatText" width = "100%" height = "32" /> & Lt; S: button label = "send" enabled = "{chatText.text.length> gt;" click = '{model.send (chattext.text); ChatText.text = ""} '/ & gt;

In addition, I do not think there is anything wrong with a visual component which is handling its idea logic ...


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -