Is there a way to force the order of callback invocations with Lift
forms,or at least ensure that on SubmitUnit callback is invoked last?
I have a form where new text-boxes are added dynamically via ajax; and
when the form is submitted the onSubmitUnit is called before the
callbacks of the new fields are invoked.
I put up a sample code at https://github.com/notnoop/lift-callbacks .
The relavent code is the index.html template
(https://github.com/notnoop/lift-callbacks/blob/master/src/main/webapp/index.html)
associated with the helloworld snippet
(https://github.com/notnoop/lift-callbacks/blob/master/src/main/scala/code/snippet/HelloWorld.scala):
class HelloWorld extends StatefulSnippet {
def dispatch = {
case _ => render
}
var initialized = false
var a = ""
def render = {
".addField" #> SHtml.ajaxButton("Add field", () => {
JsCmds.SetHtml("field", SHtml.text(a, {t=>
initialized = true
a = t
println("Initialized: " + t)
}))}) &
"type=submit" #> SHtml.onSubmitUnit(process _)
}
def process() = {
println("Processing")
if (!initialized) {
S.error(<p>Field hasn't been initialized</p>)
} else {
S.notice(<p>Field has been initialized and is "{ a }"</p>)
}
}
}
When the user click on the "Add field" button, a textbox is added to
the form. However, when the user fills the box and hits submit, the
error "Field hasn't been initialized is reported", with the logger
emitting "Processing" before it emits "Initialized".
Known workaround, changing .text to .ajaxText solves the problem, as
"blurring" the text box forces the callback before the onSubmit
callback is invoked.
Is there a better way of handling this?
Regards,
Mahmood
--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
> Please see S.formGroup. This allows you to put different fields into
> different execution order groups. Put the submit/processing logic in a high
> formGroup (I use 1,000 for my projects).
>
> Hope this helps.
Thanks a lot! This solved my problem.
For future readers, I just needed to modify the line
"type=submit" #> SHtml.onSubmitUnit(process _)
to
"type=submit" #> S.formGroup(1000) {
SHtml.submit("Submit", process)
}
I couldn't get it working with SHtml.onSubmitUnit, so I switched to
SHtml.submit().
- Mahmood
> Greetings,
>
>> Please see S.formGroup. This allows you to put different fields into
>> different execution order groups. Put the submit/processing logic in a high
>> formGroup (I use 1,000 for my projects).
>>
>> Hope this helps.
>
> Thanks a lot! This solved my problem.
>
> For future readers, I just needed to modify the line
>
> "type=submit" #> SHtml.onSubmitUnit(process _)
>
> to
>
> "type=submit" #> S.formGroup(1000) {
> SHtml.submit("Submit", process)
> }
But isn't the submit put in a form group automatically if not form group
is specified? At least that's what I gather from reading the source.....
It is put in group 1 but this shouldn't matter if all other elements are
in group 0...
/Jeppe
>> For future readers, I just needed to modify the line
>> "type=submit" #> SHtml.onSubmitUnit(process _)
>> to
>> "type=submit" #> S.formGroup(1000) {
>> SHtml.submit("Submit", process)
>> }
>
> But isn't the submit put in a form group automatically if not form group
> is specified? At least that's what I gather from reading the source.....
You are correct when using SHtml.submit, so formGroup isn't needed
here. However, a new formGroup is only created in submit() and
button(), but not in onSubmitUnit (onSubmitImpl) nor submitButton.
Should all these methods create a formGroup of 1?
- Mahmood
- Mahmood
--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Thanks.
- Mahmood
P.S. I thought I created one earlier, but couldn't see it. I
apologize if I created a duplicate somehow.