At my company, we prefer to keep all of the form text, attributes, and styling in the template, and then use onSubmit to bind a call back. Unfortunately, onSubmit does not work for radio buttons. Here is an example of the snippet code:
def renderDeactivationForm(in: NodeSeq): NodeSeq = {
(
"name=reason" #> SHtml.onSubmit(reason set _)
)(in) ++ SHtml.hidden(processDeactivation)
}
And a trimmed down version of the template code:
<div class="lift:DeactivationSnippet.renderDeactivationForm">
<form id="deativate_form" class="lift:form.ajax">
<h3>Reason for deactivating: </h3>
<ul class="choices">
<li>
<label>
<input type="radio" name="reason"
value="This is temporary. I'll be back.">
<span>This is temporary. I'll be back.</span>
</label>
</li>
...
</ul>
...
<input type="submit" value="Confirm"/>
</form>
</div>
When I run the page, each radio button has a unique name, so it no longer acts as a radio button. I think this is a bug, since in the onSubmitImpl code, it attempts to handle the situation where a node in the given NodeSeq has the same name as another radio button, however the function receives a NodeSeq containing only one input at a time, so every time it caches the name, it immediately throws it away. Is there a workaround I can use in my selector?
I am able to fix this by using SHtml.radio or adding a hidden element for processing, but this means I have to specify all the attributes in the Lift code. This will work for the time being, but I can see this being an issue elsewhere in our code.
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code