Skip to content

Commit dec472b

Browse files
author
graeme
committed
fix for GRAILS-344
git-svn-id: https://svn.codehaus.org/grails/trunk@1699 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent c8bbb83 commit dec472b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/grails/grails-app/taglib/FormTagLib.groovy

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,50 @@ class FormTagLib {
2929
* Creates a new text field
3030
*/
3131
def textField = { attrs ->
32-
attrs.type = "text"
32+
attrs.type = "text"
33+
attrs.tagName = "textField"
3334
field(attrs)
3435
}
3536
/**
3637
* Creates a hidden field
3738
*/
3839
def hiddenField = { attrs ->
3940
attrs.type = "hidden"
41+
attrs.tagName = "hiddenField"
4042
field(attrs)
4143
}
4244
/**
4345
* Creates a submit button
4446
*/
4547
def submitButton = { attrs ->
4648
attrs.type = "submit"
49+
attrs.tagName = "submitButton"
4750
field(attrs)
4851
}
4952
/**
5053
* A general tag for creating fields
5154
*/
52-
def field = { attrs ->
55+
def field = { attrs ->
56+
if(!attrs.name && !attrs.field) {
57+
throwTagError("Tag [$tagName] is missing required attribute [name] or [field]")
58+
}
59+
attrs.remove('tagName')
60+
61+
if(attrs.field)
62+
attrs.name = attrs.remove('field')
63+
64+
attrs.id = (!attrs.id ? attrs.name : attrs.id)
65+
66+
def val = attrs.remove('bean')
67+
if(val) {
68+
if(attrs.name.indexOf('.'))
69+
attrs.name.split('\\.').each { val = val?."$it" }
70+
else {
71+
val = val[name]
72+
}
73+
attrs.value = val
74+
}
75+
attrs.value = (attrs.value ? attrs.value : "")
5376
out << "<input type='${attrs.remove('type')}' "
5477
attrs.each { k,v ->
5578
out << k << "=\"" << v << "\" "

0 commit comments

Comments
 (0)