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

Emitting an event from inside a custom input component #326

Closed
iakhator opened this issue Jul 13, 2022 · 5 comments
Closed

Emitting an event from inside a custom input component #326

iakhator opened this issue Jul 13, 2022 · 5 comments
Assignees
Labels
🪄 enhancement New feature or request
Milestone

Comments

@iakhator
Copy link

Describe the feature

I have a custom input component as below that emits an event but it doesn't get to the parent.
I can comfortably do this in Vue Formulate without issue. I would like this feature if it can be added as our app heavily rely on
Global custom inputs

// ToggleCheck Component
<template>
  <div>
    <input
      :id="context.id"
      type="checkbox"
      :value="context._value"
      @input="handleChange"
    />
  </div>
</template>
<script>
export default {
  name: "ToggleCheck",
  emits: ["change"],
  props: {
    context: {
      type: Object,
      required: true,
    },
  },
  methods: {
    handleChange(event) {
      this.$emit("change", event);
    },
  },
};
</script>
inside the parent component I have this
<FormKit
      type="ToggleCheck"
      label="inputing"
      v-model="myNetworkToggle"
      @change="eventMethod"
    />

input config
inputs: {
    ToggleCheck: createInput(ToggleCheck)

  },
@iakhator iakhator added the 🪄 enhancement New feature or request label Jul 13, 2022
@justin-schroeder justin-schroeder added this to the Beta 10 milestone Jul 14, 2022
@justin-schroeder justin-schroeder self-assigned this Jul 14, 2022
@justin-schroeder
Copy link
Member

FWIW — Vue 3 doesn’t like arbitrary events being emitted from components. It will throw a warning statement when you do this. Related RFC here: vuejs/rfcs#204

@justin-schroeder
Copy link
Member

@iakhator are you looking for node.input() to set the value of the input in your handleChange?

@justin-schroeder
Copy link
Member

Descoping this for now. Because vue doesn't support arbitrary events anymore, I would suggest using FormKit's own event system with node.emit('eventName', data)' and node.on('eventName', yourCallback)`

@iakhator
Copy link
Author

iakhator commented Jul 29, 2022

Thanks, @justin-schroeder, We found our way, and node.input() worked great for our use case.

@hassanbhattignomen
Copy link

@iakhator bro how you achieved it will you share your code with me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪄 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants