juek / CustomSections

Developer plugin for rapid prototyping of custom section types in Typesetter CMS
GNU General Public License v2.0
3 stars 7 forks source link

Multi image control and section refresh #21

Closed a2exfr closed 7 years ago

a2exfr commented 7 years ago

Executing gp_editor.updateSection work no good with multi image control and take only one image(last) to refresh section. I think tthis is no go or I miss something.

Seems to me this change was working good with multi image.

edit: so cached stored content also wrong edit2: may be take postC + getValues function and formdata from my pull? edit3: postC - cant work with formdata)

a2exfr commented 7 years ago

ok I got a quick solution may be you corect it a little

    $.each(values_serialized, function(i, item) {
    if( item.name.slice(-2) =="[]"){
        var test=item.name.slice(0, -2);
        data[test]=[];
    }
        });

    $.each(values_serialized, function(i, item) {
        if( item.name.slice(-2) =="[]"){
            var test=item.name.slice(0, -2);
            data[test].push(item.value);
        } else { 
            data[item.name] = item.value;
        }
        });

I dare to merge... also fix warniing empty needle when no dirprefix

juek commented 7 years ago

We could also numerically index every [], like ...

    var item_name = false;
    var new_idx = 0;
    $.each(values_serialized, function(i, item){
      if( item['name'] != item_name ){
        item_name = item['name'];
        new_idx = 0;
      }else{
        new_idx++;
      }
      item['name'] = item['name'].replace('[]', '[' + new_idx + ']');
      data[item['name']] = item['value'];
    });

But your way is smarter I guess.

juek commented 7 years ago

Um, and sorry for breaking your initially working function by using $gp.postC ;-)

a2exfr commented 7 years ago

not at all, postC is better cause in my function was ugly eval :)