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
Dave Cox

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);

Leanne Reynolds

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);

This discussion is closed. You can start a new discussion or contact Articulate Support.