Skip to content

Instantly share code, notes, and snippets.

@KabakiAntony
Created October 30, 2022 19:51
Show Gist options
  • Save KabakiAntony/c741f7cf2c8aa2a8f2a44d6657478798 to your computer and use it in GitHub Desktop.
Save KabakiAntony/c741f7cf2c8aa2a8f2a44d6657478798 to your computer and use it in GitHub Desktop.
{% extends "admin/change_form.html" %}
{% block admin_change_form_document_ready %}
{{ block.super }}
<script type="text/javascript" charset="utf-8">
const productNameInput = document.querySelector('input[name=name]');
const productSlugInput = document.querySelector('input[name=slug]');
const slugify = (val) =>{
return val.toString().toLowerCase().trim()
.replace(/&/g, '-and-') // replace & with '-and-'
.replace(/[\s\W-]+/g,'-') // replace spaces, non word chars and dashes with '-'
};
productNameInput.addEventListener('keyup',(e)=>{
productSlugInput.setAttribute('value', slugify(productNameInput.value));
})
</script>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment