Comments (9)
how many times is "Selected Page: #{id}"
printed in the console?
from opal-jquery.
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.
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.
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.
you mean there's only one button in the html?
maybe would be good to post the HTML as well
from opal-jquery.
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.
I can also click the same item X amount times, which results in X lines of "Editing Page: " in the log.
from opal-jquery.
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.
@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)
- New release HOT 1
- opal-jquery 0.4.3 does not work with opal 1.0.0 HOT 1
- ajaxComplete HOT 2
- Static version
- Doesn't work with Zepto HOT 1
- $$ is not a function HOT 3
- .offset could not be set
- on mobile can't get more than first touch HOT 1
- opal 1.1.1 compatibility problem with opal-jquery HOT 1
- Event#touch_x raises a TypeError that can't be rescued HOT 1
- did it has method load just like in jQuery ?
- Post request is not sent on production HOT 1
- #attr should return nil instead of `undefined` HOT 1
- Gem abandoned? HOT 2
- attr with two args should return self HOT 1
- Can't run specs HOT 8
- Could not get the original object from Element instance. HOT 1
- Not bundled jQuery.js with this gem? HOT 3
- opal-jquery 0.4.2 does not work with Opal 0.11 HOT 5
- Element.expose NOT working with jQuery.ui plugin - HELP
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
} seems to accumulate "on(:click)" events?
from opal-jquery.