Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paste string like "111-111-111" and "111 111 111" + #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions jquery.groupinputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ $.fn.groupinputs = function() {
// for example, inputs value before paste: [00|2 ] [33 ], need paste: 1111
// now state: [001111|2] [33 ]

var firstValue = elem[0].value,
//var firstValue = elem[0].value,
var firstValue = filterString(elem[0].value),
caretEnd = caret(elem[0]).end, // in webkit start: 2, end: 6
left = firstValue.slice(0, caretEnd), // 001111
right = firstValue.slice(caretEnd), // 2
Expand Down Expand Up @@ -222,18 +223,36 @@ $.fn.groupinputs = function() {
}
}

function filterString(str){
str=str.replace(/\s+/g, '');
str=str.replace(/\-/g, '');
return str;
}

inputs.each(function(i) {
var elem = inputs.eq(i),
maxlength = +elem.attr(MAXLENGTH);

totalMaxlength += maxlength;
inputsMaxlength.push(maxlength);

elem.on('keydown keypress keyup input paste propertychange', {
elem: elem,
index: i,
maxlength: maxlength
}, handler);
// elem.on('keydown keypress keyup input paste propertychange', {
// elem: elem,
// index: i,
// maxlength: maxlength
// }, handler);

//для старых версий jquery
elem.bind('keydown keypress keyup input paste propertychange', function(e){
e.data={
elem: elem,
index: i,
maxlength: maxlength
};
var ctx=$(elem).get(0);
handler.apply(ctx, [e]);
//handler(e);
} );
});

// opera not support paste event
Expand Down