z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.14k stars 2.81k forks source link

Extra empty item in hasMany field #1925

Closed msassa closed 6 years ago

msassa commented 6 years ago

Description:

Into the 'dealers' form add/edit, when I add a hasMany field for an addresses relation, or whatever relation, always shows one more empty item. If there are no address related, shows one empty line, if there are some item related, shows one extra empty item: image

And for any model ... here is other example with news and images: image

And I can remove the item but not add a new one, I get this error: image

Models:

class Dealer extends Model
{
    public function addresses()
    {
        return $this->hasMany(Address::class);
    }
}

class Address extends Model
{
    public function dealer()
    {
        return $this->belongsTo(Dealer::class);
    }
}

Steps To Reproduce: asd

msassa commented 6 years ago

I already knows what is causing this error. I added this

$(document).pjax('a:not(a[target="_blank"], **a[no-pjax]** )', {
    container: '#pjax-container'
});

(the ** is only to mark what I added)

So I can make the add and edit link don't load through ajax.

And that is causing this error, but I don't know why ! If load from ajax, is good, if I add that code and the parameter to the link, and load as a new page, I had an error.

msassa commented 6 years ago

Mmmm I finally found the problem. I'm including vuejs into the admin, and doing that the tag <template> used in the hasMany field is removed. So, all the field functionality is missing.

Someone has been able to include vuejs without broke something.

I need help in this, please, because I already have an advanced admin with some days of work, and need vuejs inside the admin.

Thanks.

z-song commented 6 years ago

https://github.com/vuejs/vue/issues/2051

Try to add v-pre to the template tag in vendor/encore/laravel-admin/resources/views/form/hasmany.blade.php and see if it works?

msassa commented 6 years ago

Thank you, but is not working. I try adding a v-pre to the template tag, and not work. I try wrapping the template in a div and adding the v-pre to that div, neither.

msassa commented 6 years ago

I fix the problem making 2 changes:

'template' => str_replace('"', '&quot;', $template),

And is working. I confirm with the team of vuejs that v-pre do not works on template tags. But should be.

fukalov1 commented 5 years ago

thank you! It 's work!