Closed joewiz closed 2 years ago
Fixes https://github.com/eXist-db/shared-resources/issues/52
Before this PR, saving the following test query to /db/test/templates-form-control.xq...
xquery version "3.1"; declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; declare boundary-space preserve; declare option output:method "html5"; declare option output:media-type "text/html"; import module namespace templates="http://exist-db.org/xquery/html-templating" at "templates.xqm"; (: sample HTML taken from https://www.w3schools.com/tags/att_input_type_radio.asp :) let $content := <html> <body> <h1>Test</h1> <form> <input data-template="templates:form-control" type="text" name="foo"/><br/> <input data-template="templates:form-control" type="checkbox" id="html" name="fav_language" value="HTML"/> <label for="html">HTML</label><br/> <input data-template="templates:form-control" type="checkbox" id="css" name="fav_language" value="CSS"/> <label for="css">CSS</label><br/> <input data-template="templates:form-control" type="checkbox" id="javascript" name="fav_language" value="JavaScript"/> <label for="javascript">JavaScript</label><br/> <input type="submit"/> </form> </body> </html> let $resolver := function($functionName as xs:string, $arity as xs:int) { try { function-lookup(xs:QName($functionName), $arity) } catch * { () } } return templates:apply($content, $resolver, map{})
... and calling http://localhost:8080/exist/rest/db/test/templates-form-control.xq?fav_language=HTML would return all checkboxes checked:
After this PR, loading the page will return just the "HTML" checkbox checked:
The fix also works for radio buttons:
The PR adds a test for the previously untested scenario where a set of checkbox inputs have a @value attribute.
@value
This PR was included in https://github.com/eXist-db/templating/releases/tag/v1.0.4.
Fixes https://github.com/eXist-db/shared-resources/issues/52
Before this PR, saving the following test query to /db/test/templates-form-control.xq...
... and calling http://localhost:8080/exist/rest/db/test/templates-form-control.xq?fav_language=HTML would return all checkboxes checked:
After this PR, loading the page will return just the "HTML" checkbox checked:
The fix also works for radio buttons:
The PR adds a test for the previously untested scenario where a set of checkbox inputs have a
@value
attribute.