Reputation: 32130
I want to submit a form only if a checkbox is checked (as opposed to submit a form via the checkbox)
I don't need to save the checking of the checkbox. It is similar to "I agree to EULA bla bla"
Prefer not using javascript for this
thanks
Upvotes: 2
Views: 2572
Reputation: 32130
I've solved the issue using a validates :terms_of_service, :acceptance => true
in the model and adding a checkbox in the form block.
That solved that issue quick and easy.
Upvotes: 1
Reputation: 382696
You can check if checkbox is checked or not using code like this:
var chkbox = document.getElementById('checkboxID');
if (chkbox.checked === true){
// it is checked, submit form
}
else {
// it is not checked, dont submit form
}
Upvotes: 2