Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HasMany JS Script BUG! Using multiple instance of hasMany works only one #2097

Closed
llxx-lord-xxll opened this issue May 31, 2018 · 2 comments
Closed
Labels

Comments

@llxx-lord-xxll
Copy link

  • Laravel Version: 5.5.40
  • PHP Version:7.1.7
  • Laravel-admin: 1.5.x-dev

Description:

I wanted to use the hasMany field with several forms in different tabs. But (New) was not working only the first instance. Also if i click new button to one form, it was acting weird ( Adding new fields to other forms too)

Steps To Reproduce:

By digging through the codes, i have found that the javascript code related to this was calling the element by ID. So i have changed some changes in Encore\Admin\Form\Field\HasMany class. It is now solved.

The edited lines are marked with > character.

    protected function setupScriptForDefaultView($templateScript)
    {
        $removeClass = NestedForm::REMOVE_FLAG_CLASS;
        $defaultKey = NestedForm::DEFAULT_KEY_NAME;

        /**
         * When add a new sub form, replace all element key in new sub form.
         *
         * @example comments[new___key__][title]  => comments[new_{index}][title]
         *
         * {count} is increment number of current sub form count.
         */
        $script = <<<EOT
var index = 0;

> $('.has-many-{$this->column}').on('click', '.add', function () {
> 
>     var tpl = $('template.{$this->column}-tpl');
> 
>     index++;
> 
>     var template = tpl.html().replace(/{$defaultKey}/g, index);
>     console.log($(this).parent().parent().parent());
>     $(this).parent().parent().parent().append(template);
>     //$('.has-many-{$this->column}-forms').append(template);
>     {$templateScript}
> });

$('.has-many-{$this->column}').on('click', '.remove', function () {

>     $(this).closest('.has-many-{$this->column}-form').hide();
>     $(this).closest('.has-many-{$this->column}-form').find('.$removeClass').val(1);

});

EOT;

        Admin::script($script);
    }
@stale
Copy link

stale bot commented Apr 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 23, 2019
@stale stale bot closed this as completed Apr 30, 2019
@mRamadan0101
Copy link

this not working fine
i have issue when edit form and add new first one is removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants