# Edge: Lua widgets now require using widget.new

**URL:** https://community.silverbullet.md/t/edge-lua-widgets-now-require-using-widget-new/1971
**Category:** Lua
**Created:** [March 14, 2025, 7:23pm UTC](https://community.silverbullet.md/t/edge-lua-widgets-now-require-using-widget-new/1971 "2025-03-14T19:23:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)
#### Post date: [March 14, 2025, 7:23pm UTC](https://community.silverbullet.md/t/edge-lua-widgets-now-require-using-widget-new/1971/1 "2025-03-14T19:23:00Z")

</div>

For those on the #Edge builds and using Lua to build widgets (tables returning `markdown`, `html` etc.): you now need to wrap these tables in `widget.new`, see: [https://silverbullet.md/Space%20Lua#Widgets](https://silverbullet.md/Space%20Lua#Widgets)

What you get in return for this breaking change, is the ability to attach event handlers, so you can now build a custom button widget like so:

````auto
```space-lua
function myButton(text)
  return widget.new {
    html = "<button>" .. text .. "</button>",
    events = {
      click = function()
        editor.flashNotification("Clicked " .. text)
      end
    }
  }
end
```

${myButton("Button 1")}
${myButton("Button 2")}

````

---

<div class="post-metadata">

### Author: ![zeus-web](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zeus-web/32/571_2.png) [@zeus-web](https://community.silverbullet.md/u/zeus-web)
#### Post date: [March 15, 2025, 8:05am UTC](https://community.silverbullet.md/t/edge-lua-widgets-now-require-using-widget-new/1971/2 "2025-03-15T08:05:38Z")

</div>

Great!  
I think, this again opens great possibilities!

Might come to a solution for my Idea here:

> [@Input fields (forms) to be used eg. by LUA](https://community.silverbullet.md/t/input-fields-forms-to-be-used-eg-by-lua/1842):
>
> My idea is to have the possibility to add some kind of input fields to a page and use the input from LUA scritpts. Just like the buttons we already have. That would make several usecases possible: implement calculators (enter a number and calculate something with it) Input forms to enter data for database like silverbullet objects, like #person enter search queries (e.g. for silverbullet or even other webpages by open a link with the search query) and many more slight_smileOf course one …

Already tried this out and I’m able to generate an input field, which fires an event on change of the inputtext.  
However, I could not figure out, yet, how to get to the text I put in…

Looks like I miss a puzzle piece again 🙂

My Example:

````lua
```space-lua
function myInputField(text)
  return widget.new {
    html = text .."<input type=\"text\">",
    events = {
      change = function()
        editor.flashNotification("changed " .. text)
      end
    }
  }
end

````

${myInputField("Input here: ")}

![image](https://community.silverbullet.md/uploads/default/original/2X/0/0cc3fabb5c186835a6116ed142fa48e6aff12759.png)

---

<div class="post-metadata">

### Author: ![janssen-io](https://community.silverbullet.md/user_avatar/community.silverbullet.md/janssen-io/32/1155_2.png) [@janssen-io](https://community.silverbullet.md/u/janssen-io)
#### Post date: [March 15, 2025, 9:57am UTC](https://community.silverbullet.md/t/edge-lua-widgets-now-require-using-widget-new/1971/3 "2025-03-15T09:57:14Z")

</div>

The event function doesn’t happen to receive any arguments (at this moment)?

---

<div class="post-metadata">

### Author: ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)
#### Post date: [March 15, 2025, 9:58am UTC](https://community.silverbullet.md/t/edge-lua-widgets-now-require-using-widget-new/1971/4 "2025-03-15T09:58:31Z")

</div>

It should receive the event object, but not sure I even tested it. Just print the first argument to check.

---

<div class="post-metadata">

### Author: ![zeus-web](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zeus-web/32/571_2.png) [@zeus-web](https://community.silverbullet.md/u/zeus-web)
#### Post date: [March 15, 2025, 2:54pm UTC](https://community.silverbullet.md/t/edge-lua-widgets-now-require-using-widget-new/1971/5 "2025-03-15T14:54:51Z")

</div>

Not sure, if I made it right, but all I can see as argument is:  
{name = change, data = {isTrusted = true}}

Tested this way:

````lua
```space-lua
function myInputField(text)
  print(events)
  return widget.new {
    html = text .."<input type=\"text\" id=\"1234\" name=\"JustName\" placeholder=\"input here\" >",
    events = {
      change = function(myArgs)
        print("CHANGE: " .. myArgs)
      end
      ,
      input = function(myArgs)
      print("INPUT: " .. myArgs)
      end
    }
  }
end

````

I see in the logs:  
[Lua] INPUT: {name = input, data = {isTrusted = true}}  
[Lua] CHANGE: {name = change, data = {isTrusted = true}}

I’ll dig into the widget sourcecode later on, maybe I understand what to add (but I don’t think so, to be honest 😉 )

---

<div class="post-metadata">

### Author: ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)
#### Post date: [March 15, 2025, 3:45pm UTC](https://community.silverbullet.md/t/edge-lua-widgets-now-require-using-widget-new/1971/6 "2025-03-15T15:45:07Z")

</div>

> [@zeus-web](#):
>
> [Lua] INPUT: {name = input, data = {isTrusted = true}}  
> [Lua] CHANGE: {name = change, data = {isTrusted = true}}

Ok so this suggests you do indeed get the event object (the `isTrusted` thing is part of the event), but the javascript → Lua table mapping may not be including all useful event data. I’d have to see how to handle this in a more useful way.
