Bug fix suggestion – Servings Switcher causes page reload when entering comment
-
I found a bug. Whenever I type a comment on a blog post that contains a recipe, and then switch focus to another field, the page reloads. I found a fix for the issue. The reason it happens is because the Servings Switcher code attaches a on change event to the entire body, rather than the specific Servings Switcher widget. The suggested fix I made is below. Could you please consider including this in a future version of cooked?
Thanks,
Geoff Peters
Software Developer
Vancouver BC Canada
Twitter: gpetersOld code (with problem) in cooked-functions.js:
/**** 4. Servings Switcher ****/
if ( $(‘.cooked-servings’).length ){
var servingsSelectField = $(‘.cooked-servings’).find(‘select’);
$(‘body’).on(‘change’,servingsSelectField,function(e){
e.preventDefault();
var thisVal = servingsSelectField.find(‘option:selected’).val();
window.location = thisVal;
});
}New code that I wrote (that fixes the problem), in cooked-functions.js :
/**** 4. Servings Switcher ****/
if ( $(‘.cooked-servings’).length ){
var servingsSelectField = $(‘.cooked-servings’).find(‘select’);
servingsSelectField.change(function(e){
e.preventDefault();
var thisVal = servingsSelectField.find(‘option:selected’).val();
window.location = thisVal;
});
}Thank you,
Geoff Peters
- The topic ‘Bug fix suggestion – Servings Switcher causes page reload when entering comment’ is closed to new replies.