Comments (3)
I see a couple of possible reasons why your handlers aren't being called in your examples:
In the first handler, you are a) missing periods (.
) before the classes, and b) not targeting the button elements, and in the second handler, the form id is most likely incorrect (Rails will use an underscore instead of a hyphen).
Secondly, you will probably need to wrap the whole lot in a Trestle.init
block to ensure that they are set up on all pages, dialogs, etc, particularly if you are using Turbolinks.
Thirdly, you will need to stop the event propagation to prevent rails-ujs from still processing the form submission.
Here is how I would add a simple global save confirmation handler in the current version of Trestle:
Trestle.init(function (root) {
$(root).find('[data-behavior="trestle-form"]').on('submit', function (e) {
if (!confirm('Are you sure?')) {
e.preventDefault()
e.stopImmediatePropagation()
}
})
})
Note: I am getting close to releasing an update to Trestle that uses Turbo and Stimulus, which will require a different approach.
from trestle.
Ahh thanks,
I wasn't able to notice the missing periods (.
) for my jQuery Selectors as of writing my post.
I was also able to resolve this using a general way as well, turns out the jQuery setup works just fine turns out I had a couple missing code for it to work properly
this solution I've written down earlier isn't elegant but it was able to get me to what I needed as well.
$(document).ready(function() {
$('.btn-success').click(function() {
confirm("Are you sure?");
});
});
I'll be updating the code I'm using with your suggested code since it and more targeted to the forms themselves compared to my current implementation which can help avoid a lot of mistakes down the line in my app.
from trestle.
For future references, for the current version of Trestle (0.9.5) you can try adding this to your custom.js as well
I've managed to merge both codes into one and relied on jQuery to do its thing.
$(document).ready(function() {
$('[data-behavior="trestle-form"]').on("submit", function(e) {
if (!confirm('Are you sure?')) {
e.preventDefault()
e.stopImmediatePropagation()
}
});
});
from trestle.
Related Issues (20)
- uninitialized constant custom field rails 7 HOT 3
- Changing date format HOT 3
- Option to disable form as "show" view? HOT 1
- My custom helper not is recognized HOT 2
- How i use concerns at trestle? HOT 1
- Remove Multiple Records From MODEL Page
- WebSockets / action_cable support? HOT 2
- Pagination for a custom index View
- Fix typo for Vietnamese locale HOT 1
- Direct upload or chunked file upload support? HOT 2
- Fails without sassc-rails
- Unable to locate favicon.ico in public folder HOT 1
- Best Way To Provide a Select Dropdown for belongs_to that is optional HOT 2
- Filter with a select list
- Enum Radio Button Missing Current Selection HOT 11
- Errors on check_box fields not displaying HOT 2
- Customize navbar HOT 3
- Mongoid support HOT 2
- Use importmap in Trestle HOT 6
- Fix Brazilian Portuguese translation
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.
from trestle.