Review Board 1.5.4

Fix for issue 149 - Ajax and JSON forms do not work well when submitting from JS ...

Updated 2 years, 2 months ago

Marius Danciu Reviewers
149 dchenbecker, dpp, marius, charles, joni, atsuhiko, jorge, naftoli, kris, indrajit, alexb
None LiftWeb-archive
Fix for http://github.com/dpp/liftweb/issues#issue/149

Allows sending static forms as json forms. It also works with regular json forms generated by SHtml.jsonForm but in this case  Lisft generates its own form ID so we'd have to extract it from the <form> node, perhaps with something like:

  def makeJsonForm(html: Group): NodeSeq = {
    val formId = "none:
    val form = jsonForm(json, html)
    form match {
      case Elem(_, "form", attributes, _, c @ _ *) => formId = attributes("id").toString
    }
    form
 }

However SHtml.submitJsonForm is easier to use having simple forms with user provided ID's. See below an example.
For ajaxForms there is also a little helper: def submitAjaxForm(formId: String)
Having a static form like:

	<form id="json">
		<input name="name" type="text" />
		<br />
		<input name="value" type="text" />
		<br />

		<input value="Bike" name="vehicle" type="radio" />
		<input value="Car" name="vehicle" type="radio" />
		<input value="Airplane" name="vehicle" type="radio" />
		<br />
		<select name="cars">
			<option value="volvo">Volvo</option>
			<option value="saab">Saab</option>
			<option value="opel">Opel</option>

			<option value="audi">Audi</option>
		</select>
		<button type="submit">Submit</button>
	</form>


Used something as simple as <a href="javascript:;" onclick={SHtml.submitJsonForm(jsonHandler, "json")}>Press me</a>

Will send the Ajax request containing the json-ized form. 
Review request changed
Updated 2 years, 3 months ago (November 1st, 2009, 2:19 a.m.)
Added submitAjaxForm that allows post processing after successful processing. 
Ship it!
Posted 2 years, 3 months ago (November 1st, 2009, 9:32 a.m.)
Cant see any immediate problems - lets try it out.
Ship it!
Posted 2 years, 3 months ago (November 2nd, 2009, 1:03 p.m.)
Looks good.  You can include it in M7 because it's only additive