Getting this message:
Error: cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh' i followed the demo found here: Ugly Mongrel
Here's a snip of my JS:
function(){ var $pbNum = $('<input checked="checked" id="component-pbnum-'+ _val+ '" name="component-pbnum[]'+ '" type="checkbox" value="'+ _val+ '" data-mini="true">'+ '<label for="component-pbnum-'+ _val+ '">'+ _val+ '</label>'), $pbNumChk = $($pbNum[0]).on("change", function(ev){ $pbNum.remove(); // UNCAUGHT EXCEPTION: "cannot call methods on checkboxradio prior // to initialization; attempted to call method 'refresh'" }); $pbnumList.controlgroup("container").append($pbNum); $pbNumChk.checkboxradio(); // Have also tried $pbNumChk.checkboxradio().checkboxradio("refresh") // as hinted by other answers. No difference. } i need to add checkboxradio (checkboxes in this case) dynamically, but provide the ability to remove them when they're click/tapped.
It's actually kinda frustrating how limited jQM seems to be compared to jQUI. No (documented) "destroy" method for these widgets? Anyway...
Checkboxes add to my ControlGroup just fine. When i click to remove them in a full browser, they are removed, but an exception is thrown. Everything i've found so far answers with something similar to this: https://stackoverflow.com/a/15180600/258598
Here's what i looked for: https://www.google.com/search?q=cannot+call+methods+on+checkboxradio+prior+to+initialization
i don't get it. Why is JS throwing an error about the widget when i'm removing it - and especially when it WAS initialized when it was inserted?
[EDIT]
Fixed a small typo in the $pbNum HTML string
type=checkboxfor the input? You don't need to refresh after removing. To remove a checkbox, use $(this).closest('div').remove()type=checkbox. i had tried a container removal approach, but on a touch device it had the side-effect of deleting the checkbox i tapped AND the one next to it. And as you can see, i'm not making any attempt to refresh the checkbox during its removal. Using my script sample, the checkbox is cached, and successfully deletes on touch devices as well as full browser. But the exception is thrown on a full browser in either approach (directly on the cached $pbNum or in your suggestion).