Forum Discussion
Trigger for Text Entry to Play Screen Recording Action
- 7 days ago
You're missing one closing brace for the second if block.
Here’s the corrected code with proper closing braces:
const Inputs = () => { const inputs = document.querySelectorAll('.acc-textinput'); inputs.forEach((input) => { input.setAttribute('maxlength', '10'); input.disabled = false; input.addEventListener('keyup', () => { let text = input.value; if (text.length === 10) { if (text[8] === '4' && text[9] === '4') { setVar('valueCorrect', true); console.log('Valid number: Correct placement of 4'); } else { console.log('You must enter the correct Provider NPI.'); setVar('error', true); // setting storyline variable 'error' to true after invalid entry input.disabled = true; // disable number after invalid entry } } }); }); }; setTimeout(Inputs, 100);
I’ve attached a simple example for you. The JavaScript code is included inside. This code validates a number field based on the following conditions:
1. The number is limited to 8 digits.
2. The 2nd, 6th, and 8th digits must be the number 3.
I’ve put some basic explanation in the code itself. Let me know if your slide has more than one number/text entry, so the code can be adjusted to specifically target the number entry in question. Hope you find it useful! For any further assistance, you know where to find me. :)
- ShannonTeam-8057 days agoCommunity Member
Nedim, I'm trying to replicate what you did using slightly different criteria and a different result. I used a 10-digit number, and the 9th and 10th digits must be 4. The resulting action is the slide transitions to the next slide. This isn't working. Can you take a look?
- Nedim7 days agoCommunity Member
You're missing one closing brace for the second if block.
Here’s the corrected code with proper closing braces:
const Inputs = () => { const inputs = document.querySelectorAll('.acc-textinput'); inputs.forEach((input) => { input.setAttribute('maxlength', '10'); input.disabled = false; input.addEventListener('keyup', () => { let text = input.value; if (text.length === 10) { if (text[8] === '4' && text[9] === '4') { setVar('valueCorrect', true); console.log('Valid number: Correct placement of 4'); } else { console.log('You must enter the correct Provider NPI.'); setVar('error', true); // setting storyline variable 'error' to true after invalid entry input.disabled = true; // disable number after invalid entry } } }); }); }; setTimeout(Inputs, 100);
- ShannonTeam-8057 days agoCommunity Member
Thank you!