Created
October 30, 2022 19:51
-
-
Save KabakiAntony/c741f7cf2c8aa2a8f2a44d6657478798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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