You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
The text was updated successfully, but these errors were encountered:
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.
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.
The text was updated successfully, but these errors were encountered: