How to transfer part of a page after ajax submit form in Lift (Scala)

This is probably a stupid question, but I can’t figure out how to do this. So I am new to Scala / Lift, and I read the ajax form chapter at http://simply.liftweb.net/index-4.8.html#toc-Section-4.8 , but the "RedirectTo" in this example does not seem to be a very "ayaxian " for me. Often in the case of submitting the form via ajax, you simply partially transfer the same page, right? So what I'm trying to do is completely failing right now. How to allow Lift rerender only part of the same page after submitting the form via ajax?

Any clues would be appreciated. Thanks.

Basically, I look like this:

<div id="main" class="lift:surround?with=default;at=content"> <h2>Welcome to your project!</h2> <div class="lift:Test"> <div> <form class="lift:form.ajax"> <fieldset> <label for="name">Name:</label> <input id="name" name="name" type=text> <p></p> <input id="save" type="submit" value="Save"> </fieldset> </form> </div> <div> <span id="theName">Name</span> </div> </div> </div> class Test { def render = { var name = "" def process(): JsCmd = { Thread.sleep(500) S.notice("Entered name is: %s".format(name)) Noop } "#theName " #> "This shall be updated with the name given in the form above" & "#name" #> (SHtml.text(name, name = _) ++ SHtml.hidden(process)) } } 

How to update theName when submitting a form?

+4
source share
2 answers

See http://lift.la/shtmlidmemoize-simple-ajax-updating ( Sample Code ). There is SHtml.memoize and SHtml.idMemoize , which automatically caches HTML code. Not sure why it is not used in this example in the book Simply Lift.

+2
source

Do you have a 2-step form? This poster is correct.

Save the conversion to RequestVar .

in the above example, the method you want to save displays, so the 1st memoize transform:

  private def renderTest= SHtml.memoize { render } 

Then you can save this memoized conversion to RequestVar (for 1 request) or, possibly, TransientRequestVar depending on your needs.

  private object testTemplate extends RequestVar(renderTest) 

If you want to play the conversion, from the ajax event is testTemplate.is.applyAgain.

Perhaps I misunderstood the original question, b / c, if you want to make a 2-step form, you really don't need memoize. Memoize - if something changes in your current form and you want to update it through the ajax event, that is, when you click or when changing, b / c, the form will usually not be updated if you did not ajax submit.

0
source

Source: https://habr.com/ru/post/1386204/


All Articles