Howdy -
I'm using jQM 1.4.5 & jQ 1.11.1
Essentially i am trying to edit records. One page is a listview of records where clicking on the item takes you to the edit page. This process is done by sending an ajax request to the server to return some json data about the record, then altering the form via JS and then showing the form page. The form is a pretty simple form with a few fieldsets of radio inputs. Each radio input has it's own id. The js takes the data from the json return should then set the radio buttons to checked (and uncheck everything else), then show the page. Easy right?
Here is the js for setting the radio inputs:
- function changePage( page ) {
- $('body').pagecontainer( "change", page );
- }
- function editRecord(type, id) {
- $.get( 'a.php?action=getRecord&type=' + type + '&id=' + id, function( response ) {
- if ( type == 'food' ) {
- $('#food-id').val( id );
- $('#form_food input[type="radio"]').removeAttr( 'checked' ); // clear all checked items
- $('#meal-' + response.data.meal.toString() ).attr( 'checked', 'checked' ).checkboxradio( 'refresh' );
- $('#eat-' + response.data.eat.toString() ).attr( 'checked', 'checked' ).checkboxradio( 'refresh' );
- $('#drink-' + response.data.drink.toString() ).attr( 'checked', 'checked' ).checkboxradio( 'refresh' );
- changePage( '#page-food' );
- }
- });
- }
the html for the form page is here:
- <div id='page-food' data-role="page" data-add-back-btn="true">
- <div class="ui-content">
- <form class="app_form" id="form_food" action="#" method="get">
- <input type="hidden" name="action" value="saveFood" />
- <input type="hidden" name="id" id="food_id" value="0" />
- <input type="time" name="time" id="food_time" />
- <fieldset data-role="controlgroup" data-type="horizontal">
- <input type="radio" name="meal" id="meal-0" value="0" checked="checked"><label for="meal-0">Breakfasy</label>
- <input type="radio" name="meal" id="meal-1" value="1"><label for="meal-1">Lunch</label>
- <input type="radio" name="meal" id="meal-2" value="2"><label for="meal-2">Dinner</label>
- </fieldset>
- <fieldset data-role="controlgroup" data-type="horizontal">
- <input type="radio" name="eat" id="eat-0" value="0" checked="checked"><label for="eat-0">None</label>
- <input type="radio" name="eat" id="eat-1" value="1"><label for="eat-1">A bit</label>
- <input type="radio" name="eat" id="eat-2" value="2"><label for="eat-2">A lot</label>
- </fieldset>
- <fieldset data-role="controlgroup" data-type="horizontal">
- <input type="radio" name="drink" id="drink-0" value="0" checked="checked"><label for="drink-0">None</label>
- <input type="radio" name="drink" id="drink-1" value="1"><label for="drink-1">Water</label>
- <input type="radio" name="drink" id="drink-2" value="2"><label for="drink-2">Juice</label>
- </fieldset>
- <div class="ui-grid-a ui-responsive">
- <div class="ui-block-a"><a href="#page-options" class="ui-shadow ui-btn ui-corner-all ui-mini" data-rel="back">Cancel</a></div>
- <div class="ui-block-b"><button type="submit" id="submit_food" class="ui-shadow ui-btn ui-corner-all ui-mini">SAVE</button></div>
- </div>
- </form>
- </div>
- </div>
Here is a sample JSON return:
- {"status":"success","data":{"id":"218939","drink":"2","eat":"1","meal":"3"}}
Ok so the issues:
Problem is that while the inputs are being correctly set to checked (as verified by inspecting the element), the ui is not refreshing those inputs properly. Whenever i click a record. the page is shown with sometimes the correct elements, sometimes nothing is highlighted, or a combination therein. It has NEVER actually worked as designed.
Further, if i try to do the edit function BEFORE showing the form page, i get this error in the console:
- Uncaught Error: cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh'
But, if i go to the page first and then try the edit function it does not work. NOR does changing to the page first, then resetting the radios.
I've spent hours on this bug. I do NOT want to revert to 1.2 to test out the legacy functionality. The current workaround is to change all the radio functions to selects, but i would rather have this behavior be like buttons.
Can someone verify that this is a bug? I've already pulled all my hair out.
thanks, graham