-
- What is DG3
- The different components
- Requirements for running DG3
- Installation of DG3
- Additional installation steps
- Select which web server to use
- Hello World application
- Intro to CMS
- Setting up DG3 as a CMS
- Editing pages
- More about pages and urls
- Structuring a page using the grid
- Adding menu to pages
- Add images to the application
- More formating
- Sending email from contact us
- Adding menu to template
- Deploy the web site
- Storing the pages in database
- Create record
- Auto fill field
- Field validation
- Enable save button validator
- Add new button to template
- View document
- List documents
- Fix selection in menus in template
- CRUD Create Read Update Delete
- Intro to blogs
- Add user authentication
- Bootstrap authentication
- Let user change their passords
- Add reset password
- Login dialog box
- Extending the CMS to a blog
- Extend table for blogging
- Edit blog entry
- View blog entry
- User registration
- User password validation
- User field validation
- User auto login
- User extra registration fields
Auto fill field
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:
- get the stored value from the title field using the dataconnect library that do the heavy lifting in form in DG3.
- make a slug (lowercase no space or dangerous chars) using the Django admin urlify.js library.
- store the slug in the slug field using dataconnect library
How to add a none selectable javascript that I know is installed
- Select Code editor tab
- Click button "Show generated page code"
- Add the library to the header section
- 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.