Welcome to the LimeSurvey Community Forum

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

Numeric entry, fixed width, zero-pad left, fill from right.

  • jlwood
  • jlwood's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 1 month ago - 6 years 1 month ago #164511 by jlwood
I have a situation in a survey where users are entering codes in a Multiple Short Text Field. Some of the fields need to be formatted so that the values are a fixed width (5 digits), left padded with zeros when necessary, others can except any word or brief phrase, or be left blank.
I can do this with jquery in the onchange event AFTER the numeric part is entered, but it would be easier and less error prone if users could see the values correctly as they enter them, so for example if the code is "1234" the user would see this as they type:
00000
00001
00012
00123
01234
filling the digits in from the right like a calculator, but keeping the width fixed with zero-padding on the left.
Last edit: 6 years 1 month ago by jlwood. Reason: small typo
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago - 6 years 1 month ago #164516 by tpartner
Place a mask on the input with Robin Herbots Inputmask plugin - github.com/RobinHerbots/Inputmask

I think, for your requirements, the mask script placed in the question source would be something like:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function($) {   
    $('#question{QID} input[type="text"]').inputmask(
      "9999",
      { 
        placeholder:"0", 
        numericInput: true
      }
    );
  });
</script>


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 1 month ago by tpartner.
The topic has been locked.
  • jlwood
  • jlwood's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 1 month ago #164652 by jlwood
Thank you Tony, this is working like a charm, and fixing a few other challenges to boot. I'd tried a couple of other simpler masking utilities without success but this did the trick.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose