Welcome to the LimeSurvey Community Forum

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

Text-type (e.g. "short free text", "huge free text") UpperCase + onBlur Trim

  • kmanapp
  • kmanapp's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 2 weeks ago #117763 by kmanapp
Dear friends,

I would like to seek your kindness help on how to enforce uppercase and onblur trim (whitespace) on a text type input (e.g. "short free text" or "huge free text")? Thanks.
The topic has been locked.
  • kmanapp
  • kmanapp's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 2 weeks ago #117799 by kmanapp
I solved!

Below is the code for your reference:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready( function() {
    var my_surveyId='{SID}';
    var my_groupId='{self.gid}';
    var my_quesitonId='{self.qid}';
    var my_self='{self.sgqa}';
 
//    Operate for its appearance only (but have no effect to modify its intrinsic value):  Display as UpperCase
    $('#answer{self.sgqa}').css('text-transform', 'uppercase');
 
    $('#answer{self.sgqa}').blur(function(){
//      Operate for its intrinsic value:  Trim + Transform to Uppercase
      $(this).val( $.trim( $(this).val().toUpperCase() ) );
    });
  });
</script>
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • kmanapp
  • kmanapp's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 2 weeks ago #117800 by kmanapp
Below is the code for your reference:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready( function() {
    var my_surveyId='{SID}';
    var my_groupId='{self.gid}';
    var my_quesitonId='{self.qid}';
    var my_self='{self.SGQA}';
 
//    Operate for its appearance only (but have no effect to modify its intrinsic value):  Display as UpperCase
    $('#answer{self.SGQA}').css('text-transform', 'uppercase');
 
    $('#answer{self.SGQA}').blur(function(){
//      Operate for its intrinsic value:  Trim + Transform to Uppercase
      $(this).val( $.trim( $(this).val().toUpperCase() ) );
    });
  });
</script>
The topic has been locked.
  • kmanapp
  • kmanapp's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 2 weeks ago #117801 by kmanapp
Just realise that I wrongly post this thread in "Instlalation & Update issues" forum, I have made a correct one in the "Can I do this with LimeSurvey" forum and has this URL:
www.limesurvey.org/en/forum/can-i-do-thi...ppercase-onblur-trim
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 2 weeks ago #117807 by DenisChenu

kmanapp wrote: Just realise that I wrongly post this thread in "Instlalation & Update issues" forum, I have made a correct one in the "Can I do this with LimeSurvey" forum and has this URL:
www.limesurvey.org/en/forum/can-i-do-thi...ppercase-onblur-trim

Thanks for the tip, if you can put in in our manual please : manual.limesurvey.org/Workarounds:_Manip...ime_using_Javascript

And the last time : just ask to move, we do it in one click, here : i need 4 ;)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • kmanapp
  • kmanapp's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 2 weeks ago - 9 years 2 weeks ago #117825 by kmanapp
Great, briefly added here, kindly please feel free to revise:

Text Input (e.g. "short free text", "huge free text"): Force UpperCase + onBlur Trim
manual.limesurvey.org/Workarounds:_Manip...Case_.2B_onBlur_Trim
Last edit: 9 years 2 weeks ago by kmanapp. Reason: Update the URL
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 2 weeks ago #117826 by DenisChenu

kmanapp wrote: Great, briefly added here, kindly please feel free to revise:

Text Input (e.g. "short free text", "huge free text"): Force UpperCase + onBlur Trim
manual.limesurvey.org/index.php?title=Wo...Case_.2B_onBlur_Trim

I think you don't save ;) manual.limesurvey.org/index.php?title=Wo...cript&action=history

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • kmanapp
  • kmanapp's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 2 weeks ago #117827 by kmanapp
Sorry, now I clicked "save pages". Kindly please check :)
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • kmanapp
  • kmanapp's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 2 weeks ago #117869 by kmanapp
The above codes is generally for "text questions" (i.e., "short free text", "long free text", "huge free text").

For other textual-type questions, below are the relevant code illustrating "OnBlur Trim" purpose:

For "Multiple Choice" question enabled with the "Other" option:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready( function() {
    var this_surveyId='{SID}';
    var this_groupId='{self.gid}';
    var this_quesitonId='{self.qid}';
    var this_self='{self.sgqa}';
 
    $('#answer{self.sgqa}').blur(function(){
      $(this).val( $.trim( $(this).val() ) );
    });
  });
</script>


For "List (radio)" question enabled with the "Other" option:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready( function() {
    var this_surveyId='{SID}';
    var this_groupId='{self.gid}';
    var this_quesitonId='{self.qid}';
    var this_self='{self.sgqa}text';
 
    $('#answer{self.sgqa}text').blur(function(){
      $(this).val( $.trim( $(this).val() ) );
    });
  });
</script>
The following user(s) said Thank You: Ben_V
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 2 weeks ago #117914 by DenisChenu
Another solution for all text inside a question:
Code:
$(document).on('blur',"#question{QID} input:text,#question{QID} textarea",function(){
     $(this).val( $.trim( $(this).val() ) );
});

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose