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 7 months 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 7 months 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 7 months 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 7 months 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 & Official Partner
  • LimeSurvey Community Team & Official Partner
More
9 years 7 months 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 : www.limesurvey.org/manual/Workarounds:_M...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 support - Plugins, theme and 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 7 months ago - 9 years 7 months 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
www.limesurvey.org/manual/Workarounds:_M...Case_.2B_onBlur_Trim
Last edit: 9 years 7 months 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 & Official Partner
  • LimeSurvey Community Team & Official Partner
More
9 years 7 months 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
www.limesurvey.org/manual/index.php?titl...Case_.2B_onBlur_Trim

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

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and 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 7 months 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 7 months 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 & Official Partner
  • LimeSurvey Community Team & Official Partner
More
9 years 7 months 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 support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose