question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onClick not handling all values

See original GitHub issue

Reproduction

https://formkit.link/bafcc2084a9cad6394827c2c9e68deb5

Describe the bug

I feel like I have to be doing something stupid here. I’ve been working off the multi-step form example here and sandboxing some new features I need as a proof of concept. The playground example shows a case where an onClick handler doesn’t seem to handle being passed an object. Open that example, open the dev console, and click the LogObj button. The definition for that button is:

    {
      $formkit: 'button',
      onClick: '$log({"nextStep":"bla", "test":2})',
      children: 'LogObj'
    },

The log function is defined in Playground.vue as:

  log: target => () => {
    console.log('target:', target)
  },

In the console I just see: target: {"nextStep":"bla".

At one point onClick was also handling URLs weird for me but now I can’t reproduce that in the playground. Is it possible formkit’s parsing of variables in schema values is having trouble with certain values/types being used there? Am I just wrong in assuming it can evaluate a JS object? Maybe I need to be passing a JSON string and decoding it if I want to get away with something like the above?

Environment

• OS: MacOS • Browser: Chrome • Version: 101.0.4951.64 (Official Build) (x86_64)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
totalhackcommented, Jun 9, 2022

Hey @totalhack — separate from any schema modification if you’re just trying to access literal strings such as a hardcoded URL perhaps you could use a group and name it something like “meta” and fill it with type hidden fields that contain those values you could access such as meta.redirectUrl?

Hey @andrew-boyd, just wanted to note that I took a different approach to this. Instead I just added a “fake” node to the schema that simply holds metadata, and in a wrapper to FormKitSchema I look for that and update a meta field in the data value. For example:

const schema = [
  {
    type: 'meta',
    data: {
      someTestField: "Hey you can access this elsewhere as $meta.someTestField"
    }
  },

It doesn’t seem that formkit minds that I put an invalid node in the schema, it just ignores it. This is a lot cleaner than adding groups and hidden inputs IMO.

1reaction
luan-nk-nguyencommented, May 25, 2022

@totalhack you can also put the ignore: true prop on any input and it won’t be included in the posted form data.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event Handler onclick not working in JavaScript
So there are two issue here: the first is in the way you try to access your email field's value in your "checkEmailField"...
Read more >
HTML Button onclick – JavaScript Click Event Tutorial
The value it takes, which is the function you want to execute, says it all, as it is invoked right within the opening...
Read more >
Handling Events
Giving a node an onclick attribute has a similar effect. This works for most types of events—you can attach a handler through the...
Read more >
3 Ways of Passing Multiple Parameters to the onClick ...
In this example-based article I want to quickly cover different ways to send multiple parameters to your event handling function without having ...
Read more >
How to Use React onClick Events in Class and Functional ...
In this article, we'll cover the basics of React onClick events and we'll learn to handle click events in class and functional components....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found