On Tue, Sep 22, 2009 at 7:49 PM, KP <[email protected]> wrote:
>
> Hi all.
>
> I have essentially the following setup in a website:
>
> class AjaxTest {
> def render =
> <div>
> <div id="foo">foo</div>
> {getAjaxForm}
> </div>
>
> def getAjaxForm = SHtml.ajaxForm(
> SHtml.submit("submit", () => ()),
> Run(customJSStr))
>
> def customJSStr = "document.getElementById('foo').innerHTML = '" +
> aStr + "';"
>
If aStr contains a single or double quote or a non-printable or non-ascii
character, your expression will fail (it will be invalid JavaScript).
I would suggest:
def customJSStr = "document.getElementById('foo').innerHTML = " +aStr.encJs
+ ";"
That will properly escape the string as a JavaScript string.
>
> val aStr = SHtml.a(() => SetHtml("foo", Text("baz")), Text
> ("bar")).toString
> }
>
>
>
> when aStr is displayed (with text 'bar'), the link is inactive.
>
>
> I'm using Run(customJSStr) instead of SetHtml as, in the actual app,
> the situation is slightly more complicated (and the RHS of the
> assignment operator in the javascript expression has some more stuff
> fetched from the document).
>
> Note also that if the ajaxForm uses SetHtml() instead of Run() it
> works as expected.
>
> So the question is -- is there a straightforward explanation for
> what's going on here (I'm still kinda cargo-culting lift).
>
> And, unconditional upon the answer to the last question, is there a
> way to make aStr a valid, active link (or, I guess, string
> representing one) while retaining the ability to have an arbitrarily
> complex javascript expression in customJSStr (this would actually be
> defined in a separate js file, of course).
>
>
> Thanks much,
> KP
>
> >
>
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---