Skip to content

Commit

Permalink
Merge pull request gpc#62 from guspower/master
Browse files Browse the repository at this point in the history
Functional Test And Small Documentation Update For Passing Params Through To Default Tags
  • Loading branch information
robfletcher committed Mar 20, 2012
2 parents 8ef0887 + 393c8f0 commit 2cc51c2
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/docs/guide/customizingFieldRendering.gdoc
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions test/projects/scaffolding/grails-app/conf/BuildConfig.groovy
Expand Up @@ -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"
Expand Down
@@ -0,0 +1,5 @@
package test

class CaptainController {
static scaffold = true
}
@@ -0,0 +1,5 @@
package test

class ShipController {
static scaffold = true
}
@@ -0,0 +1,7 @@
package test

class Captain {

String name

}
8 changes: 8 additions & 0 deletions test/projects/scaffolding/grails-app/domain/test/Ship.groovy
@@ -0,0 +1,8 @@
package test

class Ship {

Captain captain
String name

}
41 changes: 41 additions & 0 deletions test/projects/scaffolding/grails-app/views/ship/create.gsp
@@ -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>
@@ -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/
}

}

0 comments on commit 2cc51c2

Please sign in to comment.