Copy link to clipboard
Copied
Hey guys,
Can someone point me in the right direction for multiline text validation.
Basically i have a scrolling text widget linked to a variable. I want the person to type in multiple lines and have it validate on click of a button.
I know how to do this for a single line, but not too sure for multiline.
Basically the learner needs to type in things like:
SELECT last_name
FROM staffing
WHERE last_name = 'Smith';
(yeap its SQL and yes it must be formatted like this)
So on click of button they get a response caption. They either get it correct or incorrect.
Output is Flash.
Im thinking this might be a job for javascript, but id like to avoid that if i can.
This is possible in JavaScript. Here's a live demo in SWF output for Cp 7:
http://captivatedev.com/demo/Cp7/multilineValidation
Here's the .cptx project for download:
http://captivatedev.com/demo/Cp7/multilineValidation\MultiLine.zip
Here's the JavaScript I used:
...var answer = document.Captivate.cpEIGetValue('m_VarHandle.scrollText');
if(answer == '1\\r2\\r3\\r' || answer == '1\\r2\\r3'){
document.Captivate.cpEISetValue('m_VarHandle.isCorrect', 'Correct');
} else {
document.Captivate.cpEISetValue
Copy link to clipboard
Copied
Formatting cannot be checked, if you also talk about the line breaks at least, the case sensitivity is automatic. Maybe you'll have to look for a workaround, like with a TEB for each line and one validation? Something like:
http://blog.lilybiri.com/one-submit-button-for-multiple-text-entry-box
Lilybiri
Copy link to clipboard
Copied
Hey Lilybiri,
I did think about using single text entry for each line, but i would really like to contain it in one box as the learner has to tab between boxes to enter each line.
The uppercasing is not imperative, the main thing is that each statement (e.g SELECT, FROM etc..) is on a new line as it is teaching good coding practices.
I have done some searching but havn't had too much luck.
Copy link to clipboard
Copied
I was hoping i could do something like
Conditional action:
If var_text is equal to "SELECT last_name \n FROM employees"
to validate the text, but obviously CP ignores the \n for a new line.
Copy link to clipboard
Copied
Maybe with JS? I don't think that Captivate can 'translate' or even understand a code in a comparison with a value in a variable.
Copy link to clipboard
Copied
This is possible in JavaScript. Here's a live demo in SWF output for Cp 7:
http://captivatedev.com/demo/Cp7/multilineValidation
Here's the .cptx project for download:
http://captivatedev.com/demo/Cp7/multilineValidation\MultiLine.zip
Here's the JavaScript I used:
var answer = document.Captivate.cpEIGetValue('m_VarHandle.scrollText');
if(answer == '1\\r2\\r3\\r' || answer == '1\\r2\\r3'){
document.Captivate.cpEISetValue('m_VarHandle.isCorrect', 'Correct');
} else {
document.Captivate.cpEISetValue('m_VarHandle.isCorrect', 'Incorrect');
}
The correct answer is:
1
2
3
All on separate lines.
When the multi-line text gets to JavaScript, the line breaks are represented by "\r". However, when you place JavaScript into the Captivate JS panel inside of Captivate, you'll need to double escape the return character "\\r". Why? Because your JavaScript inside of Captivate is interpreted at the Flash level first before it hits the browser (JS level).
You'll also notice that I'm checking for '1\\r2\\r3' (no trailing return character) AND '1\\r2\\r3\\r' (trailing return character). I found during testing that even though you hit RETURN at the end and then BACKSPACE... the "\\r" return character still remains at the end... meaning even though to the end user it looks like there's no trailing return character... there really is. It took me a while to figure this one out...
Jim Leichliter
Copy link to clipboard
Copied
Thanks a plenty Jim. I appreciate the time you dedicated to solving this issue.
I will give this a go and let you know if i hit any bumps along the road.
Cheers.