Fórumok

Problem with Alloy UI checkbox

thumbnail
Gurumurthy Godlaveeti, módosítva 11 év-val korábban

Problem with Alloy UI checkbox

Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2011.08.12. Legújabb bejegyzések
Hello There ,

I used alloy ui fields in my jsp . The alloy UI check boxes are not working exactly .

<aui:form name="some xyz" usenamespace="true">
<aui:input type="checkbox" name="first" id="first" value="1" onclick="showValue(this.id);" />
<aui:input type="checkbox" name="second" id="second" value="2" onclick="showValue(this.id);" />
</aui:form>
<aui:script>
        function showValue(checkboxId){
            alert(document.getElemntById(checkboxId).value) ;
        }
<aui:script>
</aui:script></aui:script>


But alloy ui check boxes are not giving exact values . Am i missed any point or is alloy ui check box having a problem ?
thumbnail
Pankaj Kathiriya, módosítva 11 év-val korábban

RE: Problem with Alloy UI checkbox

Liferay Master Bejegyzések: 722 Csatlakozás dátuma: 2010.08.05. Legújabb bejegyzések
Hi Gurumurthy,

What exact you are facing?
If you are getting alert true when you uncheck checkbox, and alert false while checking checkbox then its correct behaviour.


Thanks,
Pankaj
thumbnail
Gurumurthy Godlaveeti, módosítva 11 év-val korábban

RE: Problem with Alloy UI checkbox

Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2011.08.12. Legújabb bejegyzések
Hello Pankaj Kathiriya ,
Actually my alloy ui check box fields are having same name so when i use to get the value of those fields , it's wrong values .

<aui:input name="interests" type="checkbox" value="Hockey" />
<aui:input name="interests" type="checkbox" value="Cricket" />
<aui:input name="interests" type="checkbox" value="Chess" />

And My Javascript code is

document.getElementsByName("interests").value ;

So the above javascript line is giving nothing because of aui made checkbox field names as interestsCheckbox . I found it by using Inspect Element concept of Browser and then i called like below .


document.getElementsByName("interestsCheckbox").value ;


So actually it has to give values of selectedCheckboxes , means Hockey,Cricket,Chess but it's giving either (ON/OFF ) or (True/False) values .

I just observed the generated HTML/Javascript code in browser using Inspect Element (Right click on a particular field -> select Inspect Element Option -> see the generated code for that particular field ) and i found that there was no "Value" attribute for checkbox fields .

So how can i get the values of checkboxes in my requirement .


Thanks ,
Gurumurthy .G
thumbnail
Walter Christian Guardia Casas, módosítva 11 év-val korábban

RE: Problem with Alloy UI checkbox

Regular Member Bejegyzések: 127 Csatlakozás dátuma: 2010.05.05. Legújabb bejegyzések
Hello,

One sample that could help:

<aui:field-wrapper name="newVehicle" label="is-new-vehicle-asked">
<aui:input cssClass="primary-ctrl" name="newVehicle" type="radio" label="Si" value="true" onClick="javascript:showValue(this.id)"/>
<aui:input cssClass="primary-ctrl" name="newVehicle" type="radio" label="No" value="false" / >
</aui:field-wrapper>

<aui:script>
window.showValue = function (checkboxId) {
alert(checkboxId) ;
};
</aui:script>

In server side you can obtein the value use this ParamUtil.getBoolean(actionRequest, "newVehicle")

I hope this could help you
thumbnail
Gurumurthy Godlaveeti, módosítva 11 év-val korábban

RE: Problem with Alloy UI checkbox

Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2011.08.12. Legújabb bejegyzések
Hello Walter Christian Guardia Casas ,

Thank you for replying .

If i use radio button then i can select anyone of both , not both at a time . so it won't match to my requirement .

As per check boxes , i am getting same ON/OFF or True/False values to server side .

Thanks ,
Gurumurthy. G
thumbnail
Avinash R, módosítva 10 év-val korábban

RE: Problem with Alloy UI checkbox

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.09.19. Legújabb bejegyzések
Gurumurthy,

Although this is an old thread, i'll reply as it will help others too:

If you require just to get if the checkbox is checked or not then it's better to use this:


var checkbox = A.one("#checkboxId");
var checked = !(checkbox.one(":checkbox:checked") === null);


REF:
https://github.com/liferay/alloy-ui/wiki#selectors