Commit 7605f564 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

FormElementCollection : correction (trop simple ?) du bug dans la suppression...

FormElementCollection : correction (trop simple ?) du bug dans la suppression d'un item de la collection
parent 19335523
Loading
Loading
Loading
Loading
+25 −20
Original line number Diff line number Diff line
@@ -208,15 +208,11 @@ $('#{$container->getAttribute('id')}').on('click', '.collection-add-link > a', f
    var lastFieldset = $(container).children('fieldset').last();
    var index = currentCount === 0 ? currentCount : parseInt(lastFieldset.attr('data-index')) + 1;
    
    var template	= $(container).children('span').data('template');
    var templateSpan = $(container).children('span[data-template]');
    var template = templateSpan.data('template');
    template = template.replace(/__index__/g, index);

    if(currentCount === 0) {
        $(container).prepend(template);
    }
    else {
        lastFieldset.after(template);
    }
    templateSpan.before(template);

    if({$maxEnabled}) {
        if(currentCount+1 >= {$container->getMaxElements()}) {
@@ -235,19 +231,28 @@ $('#{$container->getAttribute('id')}').on('click', '.collection-delete-link' , f
    item.remove();

    var currentCount = $(container).children('fieldset').length;
    if(currentCount > 0) {
        var index = (curInd < {$this->countElements}) ? {$this->countElements} : curInd;
        $(container).children('fieldset').each(function(i, el) {
            if(i >= curPos) {
                $(el)
                    .attr('data-index', '' + index)
                    .find('select,input').attr('name', function () {
                        return this.name.replace(/\[\d+\](\[.*\])$/, '['+index+']$1');
                    });
                index++;
            }
        });
    }
//  FONCTIONNE PAS :    
//    if(currentCount > 0) {
//        var index = (curInd < {$this->countElements}) ? {$this->countElements} : curInd;
//        $(container).children('fieldset').each(function(i, el) {
//            if(i >= curPos) {
//                $(el)
//                    .attr('data-index', '' + index)
//                    .find('select,input').attr('name', function () {
//                        return this.name.replace(/\[\d+\](\[.*\])$/, '['+index+']$1');
//                    });
//                index++;
//            }
//        });
//    }
// CORRECTION (PLUS SIMPLE, TROP ?) :
//    $(container).children('fieldset').each(function(i, el) {
//        $(el)
//            .attr('data-index', '' + i)
//            .find('select,input').attr('name', function () {
//                return this.name.replace(/\[\d+\](\[.*\])$/, '['+i+']$1');
//            });
//    });

    if({$maxEnabled}) {
        if(currentCount+1 == {$container->getMaxElements()}) {