-
- 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
Field validation
In the cms we have a special field called slug for generating readable urls. A slug should be a all lowercase no space only numbers and chars field. To make sure you do not use any illegal characters, we want to filer your input. To do that, we can create a custom filter that delivers just that by adding a keydown filter in js ready on the page. The keydown let you tell the browser not to let keys trough, so for all keys we do not like, we do a preventDefault method. The keycodes is special for Javascript, and do not follow ascii or ansi strictly. The Alt, Ctrl and Shift keys also generates it's own keydown codes. One of the better lists can be found here.
The filter code
$("#slug").keydown(function (e) { // Allow: backspace, delete, tab, escape, enter if ($.inArray(e.keyCode, [46, 8, 9, 27, 13]) !== -1 || // Allow: Ctrl+A (e.keyCode == 65 && e.ctrlKey === true) || // Allow: home, end, left, right (e.keyCode >= 35 && e.keyCode <= 39) || // a-z (e.keyCode >= 65 && e.keyCode <=90) ) { // let it happen, don't do anything return; } // Ensure that it is a number or stop the keypress if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { e.preventDefault(); } });
This is how the custom field validation is created.
- Locate page properties and find the js ready tab
- Add a keydown event handler to the slug field by selecting it using the name found in element properties on field and adding the CSS id selector #.
- Check for keys you want to let thru and return immediately. We do this for backspace, delete, tab, esc, enter, ctrl+a the cursor and home keys and for a-z in any form.
- make sure we do not let any other keys thru except for unshifted numbers and numbers on the keypad