Getting ID of a button (well, in this case)

0
Hi everybody, I’ve got a case where I click a specific button and it needs to change a value in the background. This isn’t really the problem. The thing I’d like to know is, if it is possible to check which button was pressed. So is it possible to get the Name of the button pressed in a nanoflow? And, maybe you know as well, is it possible to change the style of the button after clicking it? For example: i’d like to change the color when clicked. Hope you can help!  All the best Laurens  
asked
1 answers
3

Hi Laurens,

I think the easiest solution is to give every button it's own flow, calling the same subflow with as a parameter which button was used. If this is not a solution for you, I guess you will have to add your own custom JavaScript/Jquery on the page listening to clickevents (https://gomakethings.com/listening-for-click-events-with-vanilla-javascript/). As far as I know, this isn't automatically done in the window.

You can save the clicked elements in the log or somewhere else (https://stackoverflow.com/questions/12743007/can-i-add-attributes-to-window-object-in-javascript). You can then retrieve it in the called nanoflow via a Javascript Action. 

Regarding your second question, it depends on how long the style change should persist. If it should revert to its original colour after clicking another button, you can just use the active pseudo class (https://www.w3schools.com/css/css_pseudo_classes.asp):

.mybuttonbecomespurpleafterclicking:active {
background-color: purple;
}

If you want to let the style change persist as long as the page, you can use a Javascript Action in your nanoflow to add a class with the desired style changes to the button:

var element = document.getElementById("ID");
// or use getElementByClass("classname") if the button has an unique class
element.classList.add("mystylechangeclass");

Hope this helps!

answered