How to set value to p-calendar and p-dropdown using vanilla javascript
Posted: 28 Jun 2020, 15:26
I tried to set value for p-dropdown using javascript and i see the selected index value which I gave but when I tried to trigger the event using dispatchEvent it doesn't works. For p-calender I'm not able to set date value.
Code that i have tried:
select the dropdown option
document.querySelector("p-dropdown[formcontrolname='secque']").getElementsByTagName("select")[0].options[1].selected = true
check selected option
document.querySelector("p-dropdown[formcontrolname='secque']").getElementsByTagName("select")[0].selectedOptions
to trigger event
document.querySelector("p-dropdown[formcontrolname='secque']").getElementsByTagName("select")[0].dispatchEvent(new Event('change',{ bubbles: true }))
document.querySelector("p-dropdown[formcontrolname='secque']").getElementsByTagName("select")[0].dispatchEvent(new Event('change'))
also tried with same with event "select" , "input"
for datepicker
document.querySelector("p-calendar[formcontrolname='dob']").getElementsByTagName("input")[0].value="24-01-1995"
any solution ??
Thanks in advance
Code that i have tried:
select the dropdown option
document.querySelector("p-dropdown[formcontrolname='secque']").getElementsByTagName("select")[0].options[1].selected = true
check selected option
document.querySelector("p-dropdown[formcontrolname='secque']").getElementsByTagName("select")[0].selectedOptions
to trigger event
document.querySelector("p-dropdown[formcontrolname='secque']").getElementsByTagName("select")[0].dispatchEvent(new Event('change',{ bubbles: true }))
document.querySelector("p-dropdown[formcontrolname='secque']").getElementsByTagName("select")[0].dispatchEvent(new Event('change'))
also tried with same with event "select" , "input"
for datepicker
document.querySelector("p-calendar[formcontrolname='dob']").getElementsByTagName("input")[0].value="24-01-1995"
any solution ??
Thanks in advance