automatically fill slug field while typing
This commit is contained in:
18
passbook/core/static/js/passbook.js
Normal file
18
passbook/core/static/js/passbook.js
Normal file
@ -0,0 +1,18 @@
|
||||
function convertToSlug(Text) {
|
||||
return Text
|
||||
.toLowerCase()
|
||||
.replace(/[^\w ]+/g, '')
|
||||
.replace(/ +/g, '-')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
const $source = $('input[name=name]');
|
||||
const $result = $('input[name=slug]');
|
||||
|
||||
const typeHandler = function (e) {
|
||||
$result.val(convertToSlug(e.target.value));
|
||||
}
|
||||
|
||||
$source.on('input', typeHandler) // register for oninput
|
||||
$source.on('propertychange', typeHandler) // for IE8
|
Reference in New Issue
Block a user