• Resolved geoff.peters

    (@geoffpeters)


    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: gpeters

    Old 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

    • This topic was modified 7 years, 6 months ago by geoff.peters.
    • This topic was modified 7 years, 6 months ago by geoff.peters.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Bug fix suggestion – Servings Switcher causes page reload when entering comment’ is closed to new replies.