I’m trying to stop a form submission if a specific field is filled in. It appears that returning false doesn’t cancel the ajax event when built using stimulus.
import { Controller } from 'stimulus'
export default class extends Controller {
static targets = [ 'url' ]
before() {
if (this.urlTarget.value != '') {
console.log('gotcha')
return false
}
}
}
= form_with url: 'someurl', data: { controller: 'contact', action: 'ajax:before->contact#before' } do |f|
.url= f.text_field :url, data: { target: 'contact.url' }
.submit= f.button 'Send Email'