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

2
.gitignore vendored
View file

@ -189,5 +189,5 @@ pyvenv.cfg
pip-selfcheck.json
# End of https://www.gitignore.io/api/python,django
static/
/static/
local.env.yml

View file

@ -8,7 +8,8 @@ from passbook.core.models import Application, Provider
class ApplicationForm(forms.ModelForm):
"""Application Form"""
provider = forms.ModelChoiceField(queryset=Provider.objects.all().select_subclasses())
provider = forms.ModelChoiceField(queryset=Provider.objects.all().select_subclasses(),
required=False)
class Meta:

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

View file

@ -24,6 +24,7 @@
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/patternfly.min.js' %}"></script>
<script src="{% static 'js/passbook.js' %}"></script>
{% block scripts %}
{% endblock %}
<div class="modals">