Giter VIP home page Giter VIP logo

Comments (9)

elia avatar elia commented on June 2, 2024

how many times is "Selected Page: #{id}" printed in the console?

from opal-jquery.

simonsen78 avatar simonsen78 commented on June 2, 2024

Once for every time I click a Page item in the list:

LOG:

Selected Page: 88
Selected Page: 4
Selected Page: 2
< here I click the button >
Editing page: 88!
Editing page: 4!
Editing page: 2!

from opal-jquery.

elia avatar elia commented on June 2, 2024

ok, try checking the size of @page_edit_btn with something like:

puts @page_edit_btn.size

if it's more than one, you may need to adjust your selector

from opal-jquery.

simonsen78 avatar simonsen78 commented on June 2, 2024

I put the code at the end of the "select_page" method:

puts "Page edit button size: #{@page_edit_btn.size}"

LOG:
Selected Page: 88
Page edit button size: 1
Selected Page: 4
Page edit button size: 1
Selected Page: 6
Page edit button size: 1
Selected Page: 7
Page edit button size: 1
< button pressed here >
Editing page: 88!
Editing page: 4!
Editing page: 6!
Editing page: 7!

from opal-jquery.

elia avatar elia commented on June 2, 2024

you mean there's only one button in the html?

maybe would be good to post the HTML as well

from opal-jquery.

simonsen78 avatar simonsen78 commented on June 2, 2024

Not actually a button, but an 'a' element, styled as a button using the Materialize framework.

From the body:

...
<div class="section">
  <script src="/js/build.js">
  </script>
  <div class="row">
    <div class="col l3">
      <h4 class="thin" id="pageheader">Pages (8)</h4>
      <a class="btn-flat waves-effect waves-green" id="page-new-btn">New</a>
      <a class="btn-flat waves-effect waves-blue" id="page-edit-btn">Edit</a>
      <a class="btn-flat waves-effect waves-red disabled" id="page-delete-btn">Delete</a>
      <div class="pagewindow" id="pagelist" style="height:80%">
        <div class="pagewindowitem" id="88">Admin module</div>
        <div class="pagewindowitem" id="4">Arrests</div>
        <div class="pagewindowitem" id="2">Dashboard</div>
        <div class="pagewindowitem" id="6">History</div>
        <div class="pagewindowitem" id="1">Login</div>
        <div class="pagewindowitem" id="7">Reports</div>
        <div class="pagewindowitem" id="5">Tasks</div>
        <div class="pagewindowitem" id="3">User Account</div>
      </div>
    </div>
...

So just one "button" used to edit the selcted Page item.

from opal-jquery.

simonsen78 avatar simonsen78 commented on June 2, 2024

I can also click the same item X amount times, which results in X lines of "Editing Page: " in the log.

from opal-jquery.

elia avatar elia commented on June 2, 2024

I assume the "button" is this: <a class="btn-flat waves-effect waves-blue disabled" id="page-edit-btn">Edit</a>. If that's the case it's just how jQuery works, it will append an event each time you call .on on the event, it won't replace the old event.

A solution could be to keep track of the previous event and offload it before setting the new event.

Something like this should work:

  puts "Selected Page: #{id}"
  @page_edit_btn.off @current_event if @current_event
  @page_edit_btn.remove_class "disabled"
  @current_event = @page_edit_btn.on(:click) { edit_page( id ) }

from opal-jquery.

simonsen78 avatar simonsen78 commented on June 2, 2024
@page_edit_btn.off(:click)

This did the trick, thanks! Guess I need to brush up on my JQuery :-)

from opal-jquery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.