automatically fill slug field while typing
This commit is contained in:
parent
8bc8765035
commit
dd9cd7aa0c
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -189,5 +189,5 @@ pyvenv.cfg
|
|||
pip-selfcheck.json
|
||||
|
||||
# End of https://www.gitignore.io/api/python,django
|
||||
static/
|
||||
/static/
|
||||
local.env.yml
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
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
|
|
@ -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">
|
||||
|
|
Reference in a new issue