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

Vue instance available in click event in schema? #10

Open
lsbyerley opened this issue Sep 25, 2020 · 5 comments
Open

Vue instance available in click event in schema? #10

lsbyerley opened this issue Sep 25, 2020 · 5 comments

Comments

@lsbyerley
Copy link

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
                },
              },
            },
          ],
        },
      ],
    };
  },
@gahabeen
Copy link
Owner

gahabeen commented Sep 28, 2020

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

@hmaesta
Copy link

hmaesta commented Sep 28, 2020

@gahabeen This one was not opened by me 😅

@gahabeen
Copy link
Owner

@gahabeen This one was not opened by me 😅

Sorry about that ping ;P

@gahabeen
Copy link
Owner

gahabeen commented Oct 6, 2020

@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
Copy link

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants