Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #62 from guspower/master

Functional Test And Small Documentation Update For Passing Params Through To Default Tags
  • Loading branch information...
commit 2cc51c2f3c46a53a903e3bb942a27e37cd0935a9 2 parents 8ef0887 + 393c8f0
Rob Fletcher authored
9 src/docs/guide/customizingFieldRendering.gdoc
View
@@ -49,6 +49,15 @@ and override the template _f:input_ uses with any of these:
# @grails-app/views/\_fields/string/\_input.gsp@
# @grails-app/views/\_fields/default/\_input.gsp@
+h2. Default Behaviour - Using Grails Input Tags
+
+If no template override is found the plugin will use the standard grails input tags (e.g. _g:select_, _g:checkbox_, _g:field_) for rendering input controls.
+Using _f:field_ you can pass extra arguments (e.g. _optionKey_, _optionValue_) through to these tags by prefixing them with @input-@, e.g.
+
+{code}
+<f:field bean="person" property="gender" input-optionValue="name"/>
+{code}
+
h2. Template parameters
The _f:field_ and _f:input_ tags will pass the following parameters to your templates or to the body of _f:field_ if you use one:
2  test/projects/scaffolding/grails-app/conf/BuildConfig.groovy
View
@@ -26,7 +26,9 @@ grails.project.dependency.resolution = {
}
dependencies {
test "org.codehaus.geb:geb-spock:$gebVersion"
+ test "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
+// test "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
}
plugins {
compile ":hibernate:$grailsVersion"
5 test/projects/scaffolding/grails-app/controllers/test/CaptainController.groovy
View
@@ -0,0 +1,5 @@
+package test
+
+class CaptainController {
+ static scaffold = true
+}
5 test/projects/scaffolding/grails-app/controllers/test/ShipController.groovy
View
@@ -0,0 +1,5 @@
+package test
+
+class ShipController {
+ static scaffold = true
+}
7 test/projects/scaffolding/grails-app/domain/test/Captain.groovy
View
@@ -0,0 +1,7 @@
+package test
+
+class Captain {
+
+ String name
+
+}
8 test/projects/scaffolding/grails-app/domain/test/Ship.groovy
View
@@ -0,0 +1,8 @@
+package test
+
+class Ship {
+
+ Captain captain
+ String name
+
+}
41 test/projects/scaffolding/grails-app/views/ship/create.gsp
View
@@ -0,0 +1,41 @@
+<!doctype html>
+<html>
+<head>
+ <meta name="layout" content="main">
+ <g:set var="entityName" value="Ship" />
+ <title><g:message code="default.create.label" args="[entityName]" /></title>
+</head>
+<body>
+<a href="#create-ship" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
+<div class="nav" role="navigation">
+ <ul>
+ <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
+ <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
+ </ul>
+</div>
+<div id="create-ship" class="content scaffold-create" role="main">
+ <h1><g:message code="default.create.label" args="[entityName]" /></h1>
+ <g:if test="${flash.message}">
+ <div class="message" role="status">${flash.message}</div>
+ </g:if>
+ <g:hasErrors bean="${shipInstance}">
+ <ul class="errors" role="alert">
+ <g:eachError bean="${shipInstance}" var="error">
+ <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="\${error.field}"</g:if>><g:message error="${error}"/></li>
+ </g:eachError>
+ </ul>
+ </g:hasErrors>
+ <g:form action="save">
+ <fieldset class="form">
+ <f:with bean="${shipInstance}">
+ <f:field property="captain" input-optionValue="name"/>
+ <f:field property="name"/>
+ </f:with>
+ </fieldset>
+ <fieldset class="buttons">
+ <g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
+ </fieldset>
+ </g:form>
+</div>
+</body>
+</html>
50 test/projects/scaffolding/test/functional/grails/plugin/formfields/test/DefaultSelectSpec.groovy
View
@@ -0,0 +1,50 @@
+package grails.plugin.formfields.test
+
+import geb.spock.GebSpec
+import spock.lang.Stepwise
+
+@Stepwise
+class DefaultSelectSpec extends GebSpec {
+
+ void 'create some captains'() {
+ given:
+ go 'captain/create'
+ def form = $('form')
+
+ when:
+ form.name = name
+ form.create().click()
+
+ then:
+ $('.message').text() ==~ /Captain \d+ created/
+
+ where:
+ name << ["Kirk", "Khan"]
+ }
+
+ void 'captains are listed by name when creating ship'() {
+ given:
+ go 'ship/create'
+
+ when:
+ def options = $('select option')
+
+ then:
+ options*.text() == ["Khan", "Kirk"]
+ }
+
+ void 'kirk is captain of the enterprise'() {
+ given:
+ def form = $('form')
+
+ when:
+ form.'captain.id' = "Kirk"
+ form.name = "Enterprise"
+
+ form.create().click()
+
+ then:
+ $('.message').text() ==~ /Ship \d+ created/
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.