I have a form inside a modal with 3 inputs. The first two are hours and I need to update the value of second hour when the first one change.
I've successfully connected the Stimulus controller to the form and I can show it in console. This is my controller code:
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ 'hour_start', 'hour_finish' ];
connect() {
console.log(this.hour_startTarget);
}
update() {
alert('Changed');
}
}
The connect is working properly and print on console:
<input class="form-control string required form-control datetimepicker" data-target="dtpicker.hour_start" data-action="change->dtpicker#update" required="required" aria-required="true" type="text" name="order[hour_start]" id="order_hour_start">
But when I change the value of this input, the alert is not popping up...
I also tried to ommit the change since its the default action for input, but the alert still doesn't show up.
And also tried with plain event listener on js like this:
const handleHourStart = () => {
let hourStart = document.getElementById('order_hour_start');
hourStart.addEventListener('change', () => {
alert('Changed');
})
}
But still doesn't work. Strange thing is that the click event behave as I expected but the change doesn't...
Any ideas?