You are viewing limited content. For full access, please sign in.

Question

Question

Mask Fields

asked on September 13, 2016 Show version history

Can you mask a field that might use alphabet and numeric characters. And what if there is no pattern. Let's say I needed to mask a driver's license or an email address. Do you use regular expression within the script?

I have been playing around with the below script...Feel free to rip it apart because I am not sure if I am moving in the right direction.

$(document).ready(function () {

    $.getScript('https://forms.alliancesafetycouncil.org/forms/js/jquery.mask.min.js', function () {
        $('.dl input').mask('A', {'translation': {
                                        A: {pattern: /\w+/},
                                      }
                                });
      
       $(".dl input").blur(function () {
        if ($(this).val() == 'Hidden for security reasons') { return; }
         
        $(".dl-hide input").val($(this).val());
         
        if ($(this).val() == '') { return; }
		
         else if (/\w+/.test($(this).val())) {
            $(this).val('Hidden for security reasons');
        }
    });
    });
});

 

0 0

Replies

replied on April 5, 2017 Show version history

Hopefully this will help others with what was contributed by Scott above. I'm not anywhere near a CSS expert, so understanding which element selection is needed is beyond me at times. To get, as Scott mentioned, the password field to mask, use the full javascript piece below and only modify the "class_goes_here" section with the class listed in your Form Field.

 

$(document).ready(function () {
$('.class_goes_here input').attr('type','password');
});

 

2 0
replied on September 13, 2016

The quick and easy fix is to use an input with the type="password" attribute. You can try changing the type of an existing field on your form with this:

$('.dl input').attr('type','password');

I'm not sure how LF handles password type inputs, so this may not work 100% properly. The safer way would be to add a custom HTML section where you create a password input element, and then whenever it changes you copy that value to a hidden LF single line field. Looks like you're already trying something like that based on your code above.

1 0
replied on September 13, 2016 Show version history

I have done the following as a workaround. I know we won't have any driver's license above a certain amount so I created a pattern to reflect that. This is a workaround but it works! yes

$(document).ready(function () {

    $.getScript('https://forms.alliancesafetycouncil.org/forms/js/jquery.mask.min.js', function () {
        $('.dl input').mask('AAAAAAAAAAAAAAAAA', {'translation': {
          "A": {pattern: /(\w+)/, recursive: true }
                                      }
                                });
      
       $(".dl input").blur(function () {
        if ($(this).val() == 'Hidden for security reasons') { return; }
         
        $(".dl-hide input").val($(this).val());
         
        if ($(this).val() == '') { return; }
		
         else if (/\w+/.test($(this).val())) {
            $(this).val('Hidden for security reasons');
        }
    });
    });
});

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.