automatically fill slug field while typing

This commit is contained in:
Jens Langhammer
2019-02-21 17:01:12 +01:00
parent 8bc8765035
commit dd9cd7aa0c
4 changed files with 22 additions and 2 deletions

View 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