I’m writing a custom app and I’d like to use fw-dropdown-button and trigger a script for each click of the dropdown. I’d like to be able to pass the value of the option to the script.
For example, I have the following dropdown in index.html:
Each time user selects an element from the dropdown, the browser will emit fwOptionClick. This means you can add a event listener to it.
theActionElement.addEventListener('fwOptionClick', function actionIt(eventDetails){
log( `${eventDetails}`) // all event related details
theActionElement.value; // the value in the current selection
});
This solved my problem. Your suggestion in my index.html file just as above works perfectly.
My problem was I was trying to put the same in app.js which for some reason does not work.
function onAppActivate() {
document.querySelector('fw-dropdown-button')
.addEventListener('fwOptionClick', (e) => RunCmd(e))
}
function RunCmd(e) {
var action=e.detail.value
var training_id=$(e.target.parentElement.parentElement).find('td:nth-child(1)').text()
console.log('Selected value is', action)
console.log( "Training ID is", training_id )
}
When the app is activated, does the DOM have fw-dropdown-button ? Please check that. Also define RunCmd within the onAppActivate scope or scope above it.