Issue Details (XML | Word | Printable)

Key: GRAILS-1019
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Matthew Taylor
Reporter: Maurice Nicholson
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Grails

g:select should take a disbaled="${expr}" to allow dynamic disabling based on model state

Created: 03/Apr/07 11:56 AM   Updated: 06/Jun/08 03:23 PM
Component/s: TagLib
Affects Version/s: 0.5-RC1
Fix Version/s: 1.0.4

Time Tracking:
Not Specified

File Attachments: 1. Text File FormTagLib.2.patch (0.9 kB)
2. Text File FormTagLib.patch (0.9 kB)



 Description  « Hide
It would be nice if the <g:select /> tag took a "disabled" attribute which in turn took an expression, eg:
<g:select disabled="${canChoose}" .../>

Currently if you try this you get

<select disabled="true" .../> <!-- or -->
    <select disabled="false" .../>

which in IE and FF disables the select either way.

Here's an example implementation that does the trick, which also supports literal strings, eg, <g:select disabled="disabled" .../>

def disabled = attrs.remove("disabled")
        if (!disabled.equals(false)) {
            attrs.disabled = "disabled"
        }

The key is to only output the disabled attribute when it should be disabled - the actual value is irrelevant.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Maurice Nicholson added a comment - 12/Apr/07 10:05 AM
Actually the above doesn't work when a disabled property is NOT provided.

Here is a simplification that works with or without a disabled property:

def disabled = attrs.remove("disabled")
        if (disabled) {
            attrs.disabled = "disabled"
        }

Mingfai Ma added a comment - 14/Apr/08 08:25 AM
I got exactly the same problem. And I have patched the FormTagLib and tested it.

It's actually a deflect in HTML as in HTML, no matter disabled="true" or disabled="false", the select box is disabled. Maurice and I's patch basically make the disabled attribute be write only if the value is true.

Reference:
http://www.w3schools.com/tags/tag_select.asp


Mingfai Ma added a comment - 14/Apr/08 08:31 AM
A small change is made to write
disabled = "disabled"
rather than just
disabled

The updated version is a more standard-based way to write HTML


Mingfai Ma added a comment - 06/Jun/08 11:18 AM
This fix is not included in 1.0.3. I suppose we have a good solution and the fix is very simple. could it be included in the next release?

Matthew Taylor added a comment - 06/Jun/08 03:23 PM
Expressions that resolve to a boolean value can now be used for the disabled attrib for g:select, g:radio, and g:checkBox. String values can also be used (true,false,yes,no).