Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

check free short text against a list

  • michaelziv
  • michaelziv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 8 months ago #139840 by michaelziv
check free short text against a list was created by michaelziv
Hey there,

is there a way to check the input of a "short free text" element against a list/array of values?
I have a list of approximately 1000 strings and I cant do this with a dropdown menu, because it would be to much scrolling. So I have this script which uses the given input and makes suggestions to the user, like the google search bar. The problem with this solution is, that the user can upload the answer incomplete. Thats why I need to validate that the list given contains the exact string given by the user. Is this somehow possible with the built-in limesurvey features?

Thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 8 months ago #139844 by tpartner
Replied by tpartner on topic check free short text against a list
No, not without a HUGE question validation expression.

Have a look at this workaround - manual.limesurvey.org/Workarounds:_Manip...wers_for_text_inputs

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • michaelziv
  • michaelziv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 8 months ago #139894 by michaelziv
Replied by michaelziv on topic check free short text against a list
Thank you for your solution. I was using a script like this already, but it tranferred the content of the form anyway. Didnt matter if my check returned true or false.
Solution is pretty straightforward in my case: i forgot to add a "return" to the function call. Like this: onsubmit="return checkInput(this)"

Since I added the return, everything works fine.
Thanks for your help.
The topic has been locked.
  • michaelziv
  • michaelziv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 7 months ago - 7 years 7 months ago #141141 by michaelziv
Replied by michaelziv on topic autocomplete & conditions
Today I encountered a new issue with the autocomplete script from jqueryui.com/autocomplete/
I added the text field to a condition for another question. If a certain string is entered a new questions appears. If I scroll through the suggestions provided by the script with the arrow keys and i hit a string out of the conditions the new question appears. Same thing if I enter the string completely manually. BUT if i click a matching string, the input doesn't seem to refresh and the additional question does not appear! If I clicked the string and press an arrow key (on a pc keyboard) the input is accepted/refreshed and the question appears.
Because the survey will be carried out using mobile phones the only way a string will be selected is by "clicking" it, so I really need this to work. Does anybody know a workaround for this? :dry:
Last edit: 7 years 7 months ago by michaelziv.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #141159 by tpartner
Replied by tpartner on topic autocomplete & conditions
It sounds like you will need to put a listener on the autocomplete (probably with the select event ) that would fire the checkconditions() function on the text input.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • michaelziv
  • michaelziv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 7 months ago #141208 by michaelziv
Replied by michaelziv on topic check free short text against a list
Sorry my javascript is pretty basic, what would I add in for the .autocomplete({ select: ... }); ?
Do I add the the autocompleteselect event to both functions? Like this:
Code:
$( ".selector" ).autocomplete({
  select: function( "autocompleteselect" , ui ) {}
});  
 
$( ".selector" ).on( "autocompleteselect", function() { checkconditions() } );
?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago - 7 years 7 months ago #141218 by tpartner
Replied by tpartner on topic check free short text against a list
Since you are initializing the autocomplete, it's better to do it there. Something like this (untested):

Code:
$('#question{QID}').autocomplete({
  // Some autocomplete options go here...
  // Fire the checkconditions function
  select: function(event, ui) {
    var thisInput = $('#question{QID} input.text');
    checkconditions($(thisInput).attr('value'), $(thisInput).attr('name'), 'text');
  }
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 7 months ago by tpartner.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose