$(document).ready(function() {
    'use strict';

    $(function() {
        $('.planprices').formset({
            prefix: 'plans',
            deleteText: 'Remove price',
            addCssClass: 'btn btn-default',
            addText: 'Add another price',
            deleteCssClass: 'btn btn-default'
      });
    });

    function displayLocationForm () {
        var choice = $('#id_is_online:checked').val();

        if (choice === 'on') {
            $('#location').hide();
            $('#onlineshop').show();
        } else {
            $('#location').show();
            $('#onlineshop').hide();
        }
    }

    $(document).on('click', '.hasplan-check', function () {
        var n = $(this.checked).length;

        if (n === 0) {
            $(this).closest('.planprices').find('.hasplan').hide();
        } else {
            $(this).closest('.planprices').find('.hasplan').show();
        }
    });

    $('#id_is_online').on('change', displayLocationForm);
    displayLocationForm();
});

$(document).ready(function() {
    'use strict';

    $(function() {
        $('.planprices').formset({
            prefix: 'plans',
            deleteText: 'Remove price',
            addCssClass: 'btn btn-default',
            addText: 'Add another price',
            deleteCssClass: 'btn btn-default'
      });
    });

    function displayLocationForm () {
        var choice = $('#id_is_online:checked').val();

        if (choice === 'on') {
            $('#location').hide();
            $('#onlineshop').show();
        } else {
            $('#location').show();
            $('#onlineshop').hide();
        }
    }

    $(document).on('click', '.hasplan-check', function () {
        var choice = $(this).closest('.switch').nextAll('.hasplan').slice(0, 4);

        if (this.checked) {
            choice.show();
        } else {
            choice.hide();
        }
    });

    // Show location form if contribution is online
    $('#id_is_online').on('change', displayLocationForm);

    // Show checked formsets on load
    $('.hasplan-check:checked').closest('.switch').nextAll('.hasplan').slice(0, 4).show();

    displayLocationForm();
});

Fix plan formset handling in new contribution frontend.
Fix plan formset handling in new contribution frontend.

* On load, show plans if button is checked.
* Let users know it there are any errors if button is checked.
* Fix broken behaviour in formsets when checkbox is checked.
