Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Zsolt Balogh
aui:input checkbox checked or value?
November 5, 2009 12:51 AM
Answer

Zsolt Balogh

LIFERAY STAFF

Rank: Expert

Posts: 459

Join Date: March 23, 2009

Recent Posts

Hi,

I'm using trunk now to fix a bug, I've found a new one emoticon

The code in trunk is like this:
<aui:input type="checkbox" checked="<%=checked%>" ...

But the aui:input is using the value attribute to set the checked flag.

Which is correct? Is this a bug in the above code or the aui:input checkbox will support the checked attribute?
Gavin Wan
RE: aui:input checkbox checked or value?
November 19, 2009 10:14 PM
Answer

Gavin Wan

LIFERAY STAFF

Rank: Regular Member

Posts: 191

Join Date: September 14, 2007

Recent Posts

 1
 2    <c:when test='<%= type.equals("[color=#FF0808]checkbox[/color]") %>'>
 3        <span class="aui-form-field aui-form-checkbox">
 4
 5            <%
 6            boolean booleanValue = false;
 7
 8            if (value != null) {
 9                booleanValue = GetterUtil.getBoolean(value.toString());
10            }
11
12            booleanValue = ParamUtil.getBoolean(request, name, booleanValue);
13
14            String onClick = "AUI().one(this).previous().val(this.checked);";
15            String onClickDynamicAttribute = _getAttributeIgnoreCase(dynamicAttributes, "onclick");
16
17            if (onClickDynamicAttribute != null) {
18                onClick += onClickDynamicAttribute;
19            }
20            %>
21
22            <input id="<%= id %>" name="<%= name %>" type="hidden" value="<%= value %>" />
23
24            <input [b]<%= booleanValue ? "checked" : StringPool.BLANK %> [/b]<%= disabled ? "disabled" : StringPool.BLANK %> id="<%= id %>Checkbox" name="<%=name %>Checkbox" onclick="<%= onClick %>" type="checkbox" <%= _buildDynamicAttributes(dynamicAttributes) %> />
25        </span>
26    </c:when>
27    <c:when test='<%= type.equals("[color=#FF0808]radio[/color]") %>'>
28        <span class="aui-form-field aui-form-radio <%= inlineField ? "inline-field" : StringPool.BLANK %> <%= cssClass %> <%= first ? "aui-first" : StringPool.BLANK %> <%= last ? "aui-last" : StringPool.BLANK %>">
29            <label class="aui-form-label">
30
31                <%
32                String valueString = StringPool.BLANK;
33
34                if (value != null) {
35                    valueString = value.toString();
36                }
37                %>
38
39                <c:if test='<%= inlineLabel.equals("left") %>'>
40                    <liferay-ui:message key="<%= label %>" />
41
42                    <c:if test="<%= Validator.isNotNull(helpMessage) %>">
43                        <liferay-ui:icon-help message="<%= helpMessage %>" />
44                    </c:if>
45                </c:if>
46
47                <input [b]<%= checked ? "checked" : StringPool.BLANK %>[/b] <%= disabled ? "disabled" : StringPool.BLANK %> <%= !id.equals(name) ? "id=\"" + id + "\"" : StringPool.BLANK %> name="<%= name %>" type="radio" value="<%= valueString %>" <%= _buildDynamicAttributes(dynamicAttributes) %> />
48
49
50                <c:if test='<%= !inlineLabel.equals("left") %>'>
51                    <liferay-ui:message key="<%= label %>" />
52
53                    <c:if test="<%= Validator.isNotNull(helpMessage) %>">
54                        <liferay-ui:icon-help message="<%= helpMessage %>" />
55                    </c:if>
56                </c:if>
57            </label>
58        </span>
59    </c:when>


Basicly, value is for checkbox ; checked is for radio box
Atin Agarwal
RE: aui:input checkbox checked or value?
August 30, 2012 1:25 AM
Answer

Atin Agarwal

Rank: Junior Member

Posts: 84

Join Date: February 19, 2012

Recent Posts

Actually i have encountered this same problem.
Whenever i tried to check if the checkbox is checked or not it was always showing false even if it was checked.
Like i wrote:
<aui:input name="xyz" type="checkbox" />

And in javascript :

function validateCheckBox() {
var status = document.getElementById("<portlet:namespace />xyz").checked;
alert(status); // to see if it is checked or not
}

It was always displaying false even when i checked it, which is wrong.
After some R&D I came to know that in AUI if the input type type is checkbox then it appends "Checkbox" to the name of the field.
like in my case name of the field i gave was "xyz" but it was making : "xyzCheckbox". It automatically adds this redundant string "Checkbox" at the end of the name you give.

So if we want to let it execute we have to write something like :

function validateCheckBox() {
var status = document.getElementById("<portlet:namespace />xyzCheckbox").checked;
alert(status); // now it will display as per our assumption
}

Regards
Atin Agarwal
Suresh Nimmakayala
RE: aui:input checkbox checked or value?
March 13, 2013 3:14 PM
Answer

Suresh Nimmakayala

Rank: Liferay Master

Posts: 627

Join Date: August 17, 2004

Recent Posts

Good R&D Atin emoticon