2 <script type="text/javascript" src="<%$p%>elements/masked_input_1.3.js">
6 <& /elements/tr-input-text.html, id => $id, @_ &>
7 <script type="text/javascript">
8 <&| /elements/onload.js &>
9 var el = document.getElementById('<%$id%>');
10 el.MaskedInput = window.MaskedInput({
12 format: '<% $opt{format} %>',
13 <% $opt{allowed} ? "allowed: '$opt{allowed}'," : '' %>
14 <% $opt{typeon} ? "typeon: '$opt{typeon}'," : '' %>
16 el.value = <% $value |js_string %>;
17 % if ( $clipboard_hack ) {
18 var container = document.getElementById('<%$id%>_clipboard');
19 var KeyDownHandler = function(e) {
20 e = e || event; // IE8
21 // intercept ctrl-c and ctrl-x
22 // and cmd-c and cmd-x on mac
23 if ( ( e.ctrlKey || e.metaKey ) ) {
24 // grab contents of the field, strip out delimiters and copy to container,
25 // and select its contents so that the next "ctrl-c" copies it
27 el.select(); // just a visual hint to the user
28 var reject = /[^A-Za-z0-9]/g;
29 container.value = el.value.replace(reject, '');
32 // don't confuse the maskedinput key handlers by letting them see this
33 if (e.stopImmediatePropagation) {
34 e.stopImmediatePropagation();
37 e.returnValue = false;
38 e.cancelBubble = true;
42 var KeyUpHandler = function(e) {
44 setTimeout( function() { el.focus() } , 10);
47 var PasteHandler = function(e) {
48 setTimeout( function() {
49 el.MaskedInput.setValue(container.value);
52 if ( el.addEventListener ) {
53 el.addEventListener('keydown', KeyDownHandler);
54 container.addEventListener('keyup', KeyUpHandler);
55 container.addEventListener('paste', PasteHandler);
56 } else if ( el.attachEvent ) {
57 el.attachEvent('onkeydown', KeyDownHandler);
58 container.attachEvent('onkeyup', KeyUpHandler);
59 container.attachEvent('onpaste', PasteHandler);
64 <input type="text" id="<%$id%>_clipboard" style="position:absolute; pointer-events: none; z-index: -1; opacity:0">
71 my $id = $opt{id} || sprintf('input%04d',random_id(4));
72 my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value} || '';
74 my $clipboard_hack = $FS::CurrentUser::CurrentUser->option('enable_mask_clipboard_hack');
77 Set up a text input field with input masking.
79 <& /elements/tr-input-mask.html,
80 format => '____-__-__',
81 #typeon => '_YMDhms', # which characters in the format represent blanks
82 #allowed => '0123456789', # characters allowed in the blanks
83 ... all other options as for tr-input-text.html
86 Note that the value sent on form submission will contain the mask
87 separators, and if value/curr_value is passed, it should also be
88 formatted to fit the mask.
90 Uses masked_input_1.1.js by Kendall Conrad, available under a Creative Commons
91 Attribution-ShareAlike license.