From eff104b1e2840ad40131e7ab811448a34a896f9f Mon Sep 17 00:00:00 2001 From: FivePixels Date: Sat, 23 Apr 2022 17:48:40 -0500 Subject: Begin logic on record.js for enter to tab handling, remove skip exercise button from record page. Add info about workout in card on select page, update edit to use units if they exist on an existing workout --- app/static/js/record.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'app/static') diff --git a/app/static/js/record.js b/app/static/js/record.js index aba6785..67ad2a6 100644 --- a/app/static/js/record.js +++ b/app/static/js/record.js @@ -1,13 +1,26 @@ - // Register 'Enter' listeners on all inputs -Array.from(document.getElementsByClassName('input')) - .filter(e => e.type == 'number') - .forEach(e => e.addEventListener('keyup', function(event) { - if (event.key == 'Enter') { - // TODO implement - console.log("ENTER") - } - })) +allInputs = Array.from(document.getElementsByClassName('input')) + .filter(e => e.type == 'number'); +allInputs.forEach(e => e.addEventListener('keypress', handleEnterKey)); + +function handleEnterKey(event) { + + // add ids to each input programatically + + if (event.key = 'Enter') { + event.preventDefault(); + + //Isolate the node that we're after + const currentNode = event.target; + + //Find the current tab index. + currentIndex = [...allInputs].findIndex(el => currentNode.isEqualNode(el)) + + //focus the following element + const targetIndex = (currentIndex + 1) % allInputs.length; + allInputs[targetIndex].focus();} + +} function setReset(row, values=true) { let lbsInput = row.children[1].children[0]; -- cgit v1.2.3