slug auto populate from title input or update user manual

Hi, i’am italian my name Luigi born Italy, age 40 old year … my english elementary. Studing english from hobby.

how to populate input-text in client form from slugfy from title field .
My code:

My Image:


Idea ? how to solution ?


My solution idea use javascirpt:

{% block _footer %}
const titleInput = document.querySelector('input[name=title');
const slugInput = document.querySelector('input[name=slug]');

const slugify = (val) => {
    return val.toString().toLowerCase().trim()
        .replace(/&/g, '-and-') // replacing & with '-and-'
        .replace(/[\s\W-]+/g, '-') //replcaing spaces, non-word chars and dashes with a single '-'

titleInput.addEventListener('keyup', (e) => {
    slugInput.setAttribute('value', slugify(titleInput.value));
{% endblock %}

publish code for 24h last on github.

Hello @luigiamorfini1982
What you’re trying to do is to slugify the title?
If you’re trying to do this, the JS code you publish in the 1st response is correct, although it doesn’t seem like the right thing to do. Why? Well, you may have 2 or more Pages with the same title, so when you will try to access this object through the slug, Django will found those 2 or more Pages with the same title/slug.
The slugs are there to be differentiate one from another and access an unique object.

Ok using unique=True in slug field.
Correct use?

So sorry Luigi. Hope you resolved it already.
But yes! The field you’re gonna use as slugs should be unique, unless your Business Model say the other way