Skip to content

No way to know the source of onClick event in arrays/tabarrays #908

Open
@t27

Description

@t27

Enhancement/Bug

As a user/developer, when I have a "Button" form element inside an array/tabarray schema, and this button has an onClick handler, I should be able to access the active tab index, since the purpose of having a button inside the form would be to make tab specific changes.

Behaviour

Currently, there is no way to do so. When we click on the button from any of the tabs, the same handler is called. But there is not indication of the current state.

Investigations

I looked into the code and found the definition of the click triggerring code here

Now as a hack, I passed the scope as the third element in the handler. I was able to access the active tab array index in the 2nd parent's arrayIndex variable. (scope.$parent.$parent.arrayIndex). But obviously this change wouldn't be worth a PR since it exposes the scope. I also cant pass the array index directly since this hierarchy is specific to my use case.
We probably need to devise a generic way to provide the active indices.

scope.buttonClick = function($event, form) {
          if (angular.isFunction(form.onClick)) {
            form.onClick($event, form, scope);
          } else if (angular.isString(form.onClick)) {
          ...
        };

Is there any better way to access the current index of the source tab which triggers the event?

@json-schema-form/angular-schema-form-lead

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions