[Lift] Re: JsCmd to Actual Javascript
Well you can see thr Raw JavaScript with FireBug for example. On Lift side take a look on LiftServlet.scala convertAnswersToCometResponse. From you can see this: val ret = ar.response.toJavaScript(session, ar.displayAll) toJavaScript is a method of the internal XmlOrJsCmd class which you can find in CometActor.scala. Besides that, you don't need to explicitly use CmdPair as you can just say partialUpdate(jsCmd1 jsCmd2 ...) Br's, Marius On Dec 11, 8:38 pm, Peter Robinett pe...@bubblefoundry.com wrote: I'm trying to do a partial update in my CometActor with several Javascript commands and I'm trying to figure out how to do it. It looks like I can do partialUpdate(CmdPair(jsCmd1, jsCmd2)) but I'd like to see the raw Javascript that CmdPair represents. Bar actually running the code and looking in the browser, how do I do this? JsCmd obviously has some sort of serialization method that is called before it is sent to the browser, but it is not readily apparent to me what it is. Thanks! Peter -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: JsCmd to Actual Javascript
Very cool, thanks! On Dec 11, 10:53 am, Marius marius.dan...@gmail.com wrote: Well you can see thr Raw JavaScript with FireBug for example. On Lift side take a look on LiftServlet.scala convertAnswersToCometResponse. From you can see this: val ret = ar.response.toJavaScript(session, ar.displayAll) toJavaScript is a method of the internal XmlOrJsCmd class which you can find in CometActor.scala. Besides that, you don't need to explicitly use CmdPair as you can just say partialUpdate(jsCmd1 jsCmd2 ...) Br's, Marius On Dec 11, 8:38 pm, Peter Robinett pe...@bubblefoundry.com wrote: I'm trying to do a partial update in my CometActor with several Javascript commands and I'm trying to figure out how to do it. It looks like I can do partialUpdate(CmdPair(jsCmd1, jsCmd2)) but I'd like to see the raw Javascript that CmdPair represents. Bar actually running the code and looking in the browser, how do I do this? JsCmd obviously has some sort of serialization method that is called before it is sent to the browser, but it is not readily apparent to me what it is. Thanks! Peter -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: JsCmd
You're almost there. The second parameter to ajaxCheckbox is a function that gets called on the server when the checkbox changes: SHtml.ajaxCheckbox(thing.isActive, (toggled: Boolean) = {thing.setActive(toggled); Noop}) The Noop is needed because ajaxCheckbox expects a Boolean = JsCmd function. (I can't find a good reason for it needing a JsCmd though... Shouldn't it just be Boolean = Any or better yet Boolean = Unit?) Howver, you can replace thing.setActive(toggled) with whatever code you want to run when the checkbox is toggled. Here, toggled contains the state of the checkbox. Likewise ajaxSelect: val daysOfWeek = List(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday).map(x = (x, x)) SHtml.ajaxSelect(daysOfWeek, Full(Monday), (opt: String) = {thing.setDayOfWeek(opt); Noop}) The second parameter is the default value. The opt in the third parameter will correspond to the selected day. --j On Tue, Nov 25, 2008 at 4:11 AM, Charles F. Munat [EMAIL PROTECTED] wrote: I want to update an attribute on a model object in the database via AJAX when a checkbox is clicked on a page. I presume that ajaxCheckbox is for this purpose. Can anyone quickly give me an example of how it works? If I have an attribute called isActive, how would I create an ajaxCheckbox that would call a method on the server when the checkbox is clicked to set isActive to true or false, depending on the state of the checkbox after the click? bind(mine, xhtml, isActive - SHtml.ajaxCheckbox(thing.isActive, ???) What about selecting the day of the week from an ajaxSelect and updating dayOfWeek. Or, finally, updating a text field on blur and setting the user_name. Examples would really help. I am pretty desperate to have this done today, and several hours of playing with various combinations has left me befuddled. Doesn't help that it's 4 AM. Any and all help very greatly appreciated. Thanks, Chas. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: JsCmd
And David beat me to it... Oh well :) On Tue, Nov 25, 2008 at 5:04 AM, Jorge Ortiz [EMAIL PROTECTED] wrote: You're almost there. The second parameter to ajaxCheckbox is a function that gets called on the server when the checkbox changes: SHtml.ajaxCheckbox(thing.isActive, (toggled: Boolean) = {thing.setActive(toggled); Noop}) The Noop is needed because ajaxCheckbox expects a Boolean = JsCmd function. (I can't find a good reason for it needing a JsCmd though... Shouldn't it just be Boolean = Any or better yet Boolean = Unit?) Howver, you can replace thing.setActive(toggled) with whatever code you want to run when the checkbox is toggled. Here, toggled contains the state of the checkbox. Likewise ajaxSelect: val daysOfWeek = List(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday).map(x = (x, x)) SHtml.ajaxSelect(daysOfWeek, Full(Monday), (opt: String) = {thing.setDayOfWeek(opt); Noop}) The second parameter is the default value. The opt in the third parameter will correspond to the selected day. --j On Tue, Nov 25, 2008 at 4:11 AM, Charles F. Munat [EMAIL PROTECTED] wrote: I want to update an attribute on a model object in the database via AJAX when a checkbox is clicked on a page. I presume that ajaxCheckbox is for this purpose. Can anyone quickly give me an example of how it works? If I have an attribute called isActive, how would I create an ajaxCheckbox that would call a method on the server when the checkbox is clicked to set isActive to true or false, depending on the state of the checkbox after the click? bind(mine, xhtml, isActive - SHtml.ajaxCheckbox(thing.isActive, ???) What about selecting the day of the week from an ajaxSelect and updating dayOfWeek. Or, finally, updating a text field on blur and setting the user_name. Examples would really help. I am pretty desperate to have this done today, and several hours of playing with various combinations has left me befuddled. Doesn't help that it's 4 AM. Any and all help very greatly appreciated. Thanks, Chas. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: JsCmd
The return type is JsCmd because 80% of the time the Ajax command causes some update top be sent to the browser. So, the special case is a Noop (sometimes I do an implicit Unit - Noop) and the default case is returning the code to be rendered in the browser. On Nov 25, 2008 5:04 AM, Jorge Ortiz [EMAIL PROTECTED] wrote: You're almost there. The second parameter to ajaxCheckbox is a function that gets called on the server when the checkbox changes: SHtml.ajaxCheckbox(thing.isActive, (toggled: Boolean) = {thing.setActive(toggled); Noop}) The Noop is needed because ajaxCheckbox expects a Boolean = JsCmd function. (I can't find a good reason for it needing a JsCmd though... Shouldn't it just be Boolean = Any or better yet Boolean = Unit?) Howver, you can replace thing.setActive(toggled) with whatever code you want to run when the checkbox is toggled. Here, toggled contains the state of the checkbox. Likewise ajaxSelect: val daysOfWeek = List(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday).map(x = (x, x)) SHtml.ajaxSelect(daysOfWeek, Full(Monday), (opt: String) = {thing.setDayOfWeek(opt); Noop}) The second parameter is the default value. The opt in the third parameter will correspond to the selected day. --j On Tue, Nov 25, 2008 at 4:11 AM, Charles F. Munat [EMAIL PROTECTED] wrote: I want to update a... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: JsCmd
Shtml.ajaxCheckbox(thing.isChecked, b = {thing.setChecked(b); JsCmds.Noop}) On Nov 25, 2008 4:12 AM, Charles F. Munat [EMAIL PROTECTED] wrote: I want to update an attribute on a model object in the database via AJAX when a checkbox is clicked on a page. I presume that ajaxCheckbox is for this purpose. Can anyone quickly give me an example of how it works? If I have an attribute called isActive, how would I create an ajaxCheckbox that would call a method on the server when the checkbox is clicked to set isActive to true or false, depending on the state of the checkbox after the click? bind(mine, xhtml, isActive - SHtml.ajaxCheckbox(thing.isActive, ???) What about selecting the day of the week from an ajaxSelect and updating dayOfWeek. Or, finally, updating a text field on blur and setting the user_name. Examples would really help. I am pretty desperate to have this done today, and several hours of playing with various combinations has left me befuddled. Doesn't help that it's 4 AM. Any and all help very greatly appreciated. Thanks, Chas. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---