Skip to content

Commit 97b6128

Browse files
author
Gabriel Schulhof
committed
Controlgroup: Add example illustrating dynamically adding element
1 parent 3f0cae2 commit 97b6128

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

entries/controlgroup.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,34 @@ $( ".selector" ).controlgroup( "container" );
9999
</div>
100100
]]></html>
101101
</example>
102+
<example>
103+
<desc>Dynamically adding elements.</desc>
104+
<html><![CDATA[
105+
<div data-role="page" id="page2">
106+
<div role="main" class="ui-content">
107+
<div data-role="controlgroup" data-type="horizontal" id="the-controlgroup">
108+
<label>Yes<input type="radio" name="answers"></label>
109+
<label>No<input type="radio" name="answers"></label>
110+
</div>
111+
<a href="#" id="add-button" class="ui-btn ui-corner-all ui-shadow ui-btn-inline">Add Item</a>
112+
</div>
113+
</div>
114+
]]></html>
115+
<code><![CDATA[
116+
$( document ).on( "click", "#add-button", function() {
117+
var group = $( "#the-controlgroup" ),
118+
possibleLabels = [ "Oui", "Non", "Igen", "Nem", "Ja", "Nein" ],
119+
label = possibleLabels[ Math.round( Math.random() * ( possibleLabels.length - 1 ) ) ];
120+
121+
$( "<label>" + label + "<input type='radio' name='answers'></label>" )
122+
123+
// We append the item to the element returned by the controlgroup's container() method
124+
.appendTo( group.controlgroup( "container" ) )
125+
.children()
126+
.checkboxradio();
127+
group.controlgroup( "refresh" );
128+
});
129+
]]></code>
130+
</example>
102131
<category slug="widgets"/>
103132
</entry>

0 commit comments

Comments
 (0)