When a user adds a title, we want to automatically add the lookup url (slug) based on the values entered in the title.

How to fill a field form another field

The simplest way to do this is to add a js ready script activated by the title change field.

$("#title").change(function(event) {
	var title = dataconnect.getfield('title').value;
	var slug = URLify(title,40);
	dataconnect.setfield("slug",slug);
})

The title change code

Now you might have discovered a function called URLify and wonder where that came form. This is a function that comes form the Django admin interface framework that is installed by default in any DG3 app. The only thing you have to do is to make sure it is loaded before the change event for title is called. To do this we will add it in the page template code view as an inline header code. 

The code does the following:

  1. get the stored value from the title field using the dataconnect library that do the heavy lifting in form in DG3.
  2. make a slug (lowercase no space or dangerous chars) using the Django admin urlify.js library.
  3. store the slug in the slug field using dataconnect library

How to add a none selectable javascript that I know is installed

  1. Select Code editor tab
  2. Click button "Show generated page code"
  3. Add the library to the header section
  4. Save by save icon in the page view code

First you have to switch to the code editor tab found at the bottom of the page

Then you needs to open the generated page code

A new tab in code view appears showing the generated page html at the bottom and a area to add your own custom tode at the top.

Add code for loading the script

Make sure you save it back to the page using the save icon above the editor
<script type="text/javascript" src="{{ media_url }}admin/js/urlify.js"></script><br>

The code added to the Page header inside the generated page code view. The code used the raw livetext {{ media_url }} that simply converts to /static/files/. The nice thing about using this is if you changes the location of static/files at a later stage, it will point on the new one automatically. This is the reason it is used in most raw templates and places like this. The other part is simply pointing at the admin/js/urlify.js library that comes with Django.