In a previous post I had the problem that my form was not send with
ajax.
With the help of Marius and Timothy I got it working.
(http://groups.google.com/group/liftweb/browse_thread/thread/
d052ed7191561ef1)
I have to questions.
Now I want, after the form is submittet, to fetch an object from my DB
do something
and update the site.
I tried the following:
def add(xml: NodeSeq): NodeSeq = {
def addBookmark(): JsCmd = {
// fetch the object from DB
JsCmds.SetHtml(WebHelper.MAIN_DIV_ID,
TemplateFinder.findAnyTemplate
(WebHelper.bookmarkEdit).open_!)
}
SHtml.ajaxForm(
bind("bookmark", xml,
"url" -> SHtml.text(url, url = _),
"submit" -> SHtml.submit("add", addBookmark)
), JsCmds._Noop, addBookmark
)
}
I hoped that the addBookmark method would be invoked after the form
is submitted and that the returned SetHtml will set the new snippet
fragment (that should be processed by lift).
The new fragment is a new form:
<lift:Bookmark.edit>
<bookmark:url />
<bookmark:title />
<bookmark:submit />
</lift:Bookmark.edit>
Is there a better way to do such ajax fragment replacements? would
like to know more about.
Are the NodeSeq that should be replaced with SetHtml processed by
Lift?
The second thing is, that when I am trying to make a browser request
to view the page,
the addBookmark method is already executed. Was this intended?
with best regards
Are the NodeSeq that should be replaced with SetHtml processed by
Lift?
The second thing is, that when I am trying to make a browser request
to view the page,
the addBookmark method is already executed. Was this intended?
thank you for the answer.
Ok I will check it again set up a little example.
Is this a "lift" way workflow?
- show a page with a form
- data is submitted to snippet
- data is evaluated
- get other fragments/templates and bind the values for them
- invoke SetHtml that should replace div content on the page
> Not unless you're specifically calling templates, etc.
Do I have to load my fragments with templateFinder and then
invoke other snippet methods that are intended to process the
templates xml or is there another way so that Lift can do it.
with best regards
On 29 Dez., 20:13, Alex Boisvert <alex.boisv...@gmail.com> wrote:
> On Tue, Dec 29, 2009 at 7:44 AM, greekscala <hellectro...@gmail.com> wrote:
> > Hello,
>
> > In a previous post I had the problem that my form was not send with
> > ajax.
> > With the help of Marius and Timothy I got it working.
> > (http://groups.google.com/group/liftweb/browse_thread/thread/
> > d052ed7191561ef1<http://groups.google.com/group/liftweb/browse_thread/thread/%0Ad052ed...>
I think I found an error in the form processing, correcct me if it is
not:
This is the snippet:
class Test {
object name extends RequestVar[String]("init")
def render(xml: NodeSeq): NodeSeq = {
def printName(): JsCmd = {
Log.debug("name = " + name.is)
JsCmds.Alert("an ajax response! "+ name.is)
}
SHtml.ajaxForm(
Helpers.bind("atest", xml,
"name" -> SHtml.text(name.is, name(_)),
"submit" -> SHtml.submit("add", printName)
), JsCmds._Noop, printName
)
/*
SHtml.ajaxForm(
Helpers.bind("atest", xml,
"name" -> SHtml.text(name.is, name(_)),
"submit" -> SHtml.submit("add", printName)
) ++ SHtml.hidden(printName)
)
*/
}
}
This is the template:
<lift:surround with="default" at="col3">
<lift:Test>
<atest:name />
<atest:submit />
</lift:Test>
</lift:surround>
The problem is with the uncommented ajaxForm code, when the form is
submitted the name RequestVar is not updated. I seems that the
function
bound to the name-Textfield is not invoked. So I get back "an ajax
response! init".
But the commented ajaxForm code gives me a correnct result. If I type
"name" in the
textfield I get "an ajax response! name" back.
with best regards
Is this a "lift" way workflow?
- show a page with a form
- data is submitted to snippet
- data is evaluated
- get other fragments/templates and bind the values for them
- invoke SetHtml that should replace div content on the page
> Not unless you're specifically calling templates, etc.Do I have to load my fragments with templateFinder and then
invoke other snippet methods that are intended to process the
templates xml or is there another way so that Lift can do it.
Br's,
Marius
No there are no error messsages in the console window.
This is the generated form:
<form id="F587106754336BUG" action="javascript://"
onsubmit=";liftAjax.lift_ajaxHandler(jQuery
('#'+"F587106754336BUG").serialize(), function() { alert("an ajax
response! init");; }, null, "javascript");return false;"
postsubmit="alert("an ajax response! init");">
<input type="text" value="init" name="F5871067543340QE"/>
<input type="submit" name="F587106764335BDR" value="add"/>
</form>
Under the firebug network panel I see that there is a post ("x" is
typed value in the textfield):
F5871067543340QE x
And the response for this post is empty.
with best regards
I see that I get the predefined alert.