Skip to content

Vue instance available in click event in schema? #10

Open
@lsbyerley

Description

@lsbyerley

I'd like to call a method or emit an event from a click even in the schema but this is undefined. Is there a way to do this with this plugin? Example below

  data() {
    return {
      schema: [
        {
          type: 'text',
          label: 'Email',
          name: 'email',
          validation: 'bail|required|email',
        },
        {
          type: 'password',
          label: 'Password',
          name: 'password',
          validation: 'required',
        },
        {
          component: 'div',
          class: 'flex align-center justify-between',
          children: [
            {
              type: 'submit',
              label: 'Login',
            },
            {
              type: 'button',
              name: 'forgot-password',
              label: 'Forgot Password',
              on: {
                click() {
                  console.log(this); //undefined
                },
              },
            },
          ],
        },
      ],
    };
  },

Activity

gahabeen

gahabeen commented on Sep 28, 2020

@gahabeen
Owner

Hey @lsbyerley, sorry for the delay. Been off-grid last week!
I'll have a look.

hmaesta

hmaesta commented on Sep 28, 2020

@hmaesta

@gahabeen This one was not opened by me 😅

gahabeen

gahabeen commented on Sep 28, 2020

@gahabeen
Owner

@gahabeen This one was not opened by me 😅

Sorry about that ping ;P

gahabeen

gahabeen commented on Oct 6, 2020

@gahabeen
Owner

@lsbyerley So far there is no context bound to the event function.

Feel free to dive into it to add this feature if you want to.
https://github.com/gahabeen/vue-formulate-extended/blob/master/src/features/form-events.js

Pull requests are always appreciated.
I'm also here if you've got any question.

cjcrawford

cjcrawford commented on Oct 12, 2020

@cjcrawford

@lsbyerley if you're using ES6 you can simply change your syntax slightly to get access to your vm (this) if that's what you're after...

data() {
    return {
      schema: [
        ...
        {
          component: 'div',
          class: 'flex align-center justify-between',
          children: [
            ...
            {
              type: 'button',
              name: 'forgot-password',
              label: 'Forgot Password',
              on: {
                click: (event) => {
                  console.log(this); // VueComponent
                  console.log(event); // MouseEvent
                },
              },
            },
          ],
        },
      ],
    };
  },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Vue instance available in click event in schema? · Issue #10 · gahabeen/vue-formulate-extended