Event Handling

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
nad
Posts: 18
Joined: Sat Feb 10, 2024 1:41 pm

Event Handling

Post by nad »

SpiderBasic does an excellent job compiling BASIC to client-side JavaScript/WASM, and the JS interop is powerful.
However, for developers coming from other RAD environments, one gap becomes apparent as applications grow:
Event handling remains largely manual and JavaScript-centric.
Today, UI events typically require:
Writing explicit JavaScript functions
Manually forwarding those events via sb_event()
Dispatching them again inside BASIC using EventParameter()
While this works, it adds a layer of glue code that feels unnecessary given that SpiderBasic already controls the compilation pipeline.
Feature Wish
I’d love to see SpiderBasic provide a first-class event binding abstraction,
where common client-side events can be bound directly to BASIC procedures without explicit JavaScript wrappers.
For example (illustrative syntax only):
BindEvent(#btnPrev, "click", @PrevPage())
or
Procedure PrevPage()
pageNum - 1
EndProcedure
with SpiderBasic generating the necessary JavaScript internally.
Why this would help
Reduces boilerplate JS glue code
Makes SpiderBasic feel more like a cohesive language rather than “BASIC + JS”
Lowers the barrier for database-driven applications that rely on many UI events
Encourages larger, more maintainable SpiderBasic applications
This would not remove or limit direct JavaScript access — advanced users could still use JS when needed — but it would make SpiderBasic far more productive for common application workflows.
I believe this kind of abstraction would strengthen SpiderBasic’s position as a serious client-side development tool rather than just a syntax bridge to JavaScript.
Thank you for considering this, and for the continued work on SpiderBasic.
Fred
Site Admin
Posts: 1858
Joined: Mon Feb 24, 2014 10:51 am

Re: Event Handling

Post by Fred »

Did you tried ?

BindGadgetEvent(#Button, @ButtonHandler(), #PB_EventType_LeftClick)
nad
Posts: 18
Joined: Sat Feb 10, 2024 1:41 pm

Re: Event Handling

Post by nad »

I have code to display a page of data with a heading, and search fields in a html <table> . I'm new to spider, so maybe there is something to handle this. The proglem is when displaying the table with html there is no way to use things like buttonGadgets, so I use html "<button onclick=..... Then later in the code I have to write javascript to try and link the <button to a procedure in spiderbasic. Maybe there is a answer and I am missing something. But since spider is in control of the compile maybe it would be possible to do direct links to spider procedures for any triggers like onChange, onMouseover, onLeave etc. here is my code...
;

Code: Select all

 =========================================================
; RENDER PAGE
; =========================================================
Procedure ShowPage()
  Protected offset, sql$, resp$, rows, row, i

  html "<h3>Person Table</h3>"

  html "<button onclick=""sb('prev')"">Prev</button>"
  html " Page " + Str(pageNum) + " / " + Str(totalPages)
  html " <button onclick=""sb('next')"">Next</button>"
  html " &nbsp; Records: " + Str(totalRecords)

  offset = (pageNum - 1) * lpp

  sql$ = "SELECT * FROM person" + where$ +
         " ORDER BY " + sort$ +
         " LIMIT " + Str(lpp) +
         " OFFSET " + Str(offset)

  resp$ = ExecSQL(sql$)
  ParseJSON(0, resp$)
  rows = GetJSONMember(JSONValue(0),"rows")

  html "<table border=1 cellpadding=2 cellspacing=0>"
  html "<tr bgcolor=wheat>"
  html "<th>#</th><th>First</th><th>Last</th><th>Sex</th>"
  html "<th>Birth</th><th>Birth Place</th>"
  html "<th>Death</th><th>Death Place</th>"
  html "</tr>"

  For i = 0 To JSONArraySize(rows)-1
    row = GetJSONElement(rows,i)

    html "<tr>"
    html "<td align=right>" + Str(GetJSONInteger(GetJSONMember(row,"personNum"))) + "</td>"
    html "<td>" + GetJSONString(GetJSONMember(row,"name")) + "</td>"
    html "<td>" + GetJSONString(GetJSONMember(row,"surName")) + "</td>"
    html "<td align=center>" + GetJSONString(GetJSONMember(row,"gender")) + "</td>"
    html "<td>" + GetJSONString(GetJSONMember(row,"birthDate")) + "</td>"
    html "<td>" + GetJSONString(GetJSONMember(row,"birthPlace")) + "</td>"
    html "<td>" + GetJSONString(GetJSONMember(row,"deathDate")) + "</td>"
    html "<td>" + GetJSONString(GetJSONMember(row,"deathPlace")) + "</td>"
    html "</tr>"
  Next

  html "</table>"
EndProcedure
User avatar
Peter
Posts: 1206
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Event Handling

Post by Peter »

nad wrote: Fri Jan 16, 2026 12:28 pmThe proglem is when displaying the table with html ...
Is there a need to use an HTML table? Have you ever looked at ListIconGadget()?

BTW: There is an easier way to read the JSON. Feel free to take a look at ExtractJSONList().

P.S.: Your code seems to be missing the plus sign (html + ...)
nad
Posts: 18
Joined: Sat Feb 10, 2024 1:41 pm

Re: Event Handling

Post by nad »

This may be my answer. As a newbe, I'm in a learning curve and have a lot to learn. Spider seems to have a lot of options.
I'll give it a try..
Thanks for the help.
Post Reply