Remove/Ignore spaces at the end of text entry fields
Oct 09, 2017
Hiya,
I have built a slide that asks users to type as many protected characteristics they can remember, using text entry fields to capture their answers and trigger conditions to set a 'correct' variable to 'true' if they match certain words/phrases.
This works fine in principal but have run into problems in that it doesn't count as a match if the user adds a space at the end of their answers.
Does anyone know if there is a way to set it to recognise and ignore those spaces automatically or, will I need to add separate conditions for each of these?
3 Replies
Hi Nicola,
My experience has been that when you test the results of a text entry field, the trailing characters are ignored by Storyline. That leads me to wonder if there is something else going on with your project.
Still, if this still remains the issue, you can try and remove the remaining characters with javascript. The following code should do the trick.
Add a javascript trigger, and add code something like this to remove the trailing characters from the storyline variable TextEntry.
var p = GetPlayer();
var textentry = p.GetVar("TextEntry");
var newTextentry = textentry.replace(/^\s+|\s+$/g, '');
p.SetVar("TextEntry",Textentry);
Just to help anyone who might be copying this exactly, here's my edit as I found it wasn't working as is. I changed the last 'Textentry' needs to say 'newTextentry' and it works.
var p = GetPlayer();
var textentry = p.GetVar("TextEntry");
var newTextentry = textentry.replace(/^\s+|\s+$/g, '');
p.SetVar("TextEntry",newTextentry);
I'm finding this occurring too - although in the inverse - our quiz answers have been pasted in with spaces before and after.
Does this script work in both directions - for both the answers and the input?
And does it account for spaces at the beginning and end of the text entry?
Thanks,
This discussion is closed. You can start a new discussion or contact Articulate Support.