Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #63 from guspower/master

Adding 'from' functionality to default rendering of one-to-one/many-to-one/many-to-many
  • Loading branch information...
commit 7c441c2680caf24e5fe0880a3c7594da5f80277d 2 parents 2cc51c2 + e5a565e
Rob Fletcher authored
View
2  grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy
@@ -340,7 +340,7 @@ class FormFieldsTagLib implements GrailsApplicationAware {
private String renderAssociationInput(Map model, Map attrs) {
attrs.name = "${model.prefix?:''}${model.property}.id"
attrs.id = (model.prefix?:'')+model.property
- attrs.from = model.persistentProperty.referencedPropertyType.list()
+ attrs.from = attrs.from ?: model.persistentProperty.referencedPropertyType.list()
attrs.optionKey = "id" // TODO: handle alternate id names
if (model.persistentProperty.manyToMany) {
attrs.multiple = ""
View
24 test/unit/grails/plugin/formfields/DefaultInputRenderingSpec.groovy
@@ -29,6 +29,8 @@ class DefaultInputRenderingSpec extends Specification {
people*.save(validate: false)
}
+ private List<Person> getSimpsons() { people.findAll { it.name.contains("Simpson")} }
+
def "input for a #type.simpleName property matches '#outputPattern'"() {
given:
def model = [type: type, property: "prop", constraints: [:], persistentProperty: basicProperty]
@@ -342,6 +344,28 @@ class DefaultInputRenderingSpec extends Specification {
Set | manyToManyProperty | "many-to-many"
}
+ def "input for a #description property is a select containing only entries specified in from parameter"() {
+ given:
+ def model = [type: type, property: "prop", constraints: [:], persistentProperty: persistentProperty]
+
+ when:
+ def output = tagLib.renderDefaultInput(model, [from: simpsons])
+
+ then:
+ output =~ /select name="prop.id"/
+ output =~ /id="prop"/
+ simpsons.every {
+ output =~ /option value="$it.id" >$it.name/
+ }
+ !output.contains("Monty Burns")
+
+ where:
+ type | persistentProperty | description
+ Person | oneToOneProperty | "one-to-one"
+ Person | manyToOneProperty | "many-to-one"
+ Set | manyToManyProperty | "many-to-many"
+ }
+
def "select for a #description property with a value of #value has the correct option selected"() {
given:
def model = [type: type, property: "prop", constraints: [:], persistentProperty: persistentProperty, value: value]
Please sign in to comment.
Something went wrong with that request. Please try again.