What's happenin'?
How can I help you today?

My Account
Login | Services | Support

  • @goverstreet:
Confirm MODx Required Fields

Confirm MODx Required Fields

Change How Your ManagerManager Plugin's Required Field Pop-Up Works

December 30, 2011

ManagerManager is an essential tool for any MODx developer who looking simplify and customize their backend content management.  You are able to change field names, hide fields, arrange sections, create new tabs, and much more.  Many of the functions can be found in the example documentation, some cannot.

One of the missing items is the "mm_requireFields" function.  This function is a helpful feature as you can specify which items are absolutely necessaary to fill in prior to saving.  This can make sure your editors and bloggers don't forget overlooked and important details such as tags or summaries.  If the editor leaves a box empty, it will indicate which fields need to be corrected.

Below is an example of how to use this feature in your rules chunk:

mm_requireFields('$fields', $roles, $templates);

Simply separate the fields by commans like any other ManagerManager rule.  Currently, this only works for input fields such as text, textarea, publush date, and images.  This won't work for items such as drop-down menus since there is already a predesignated selection.

This helpful tool has one minor flaw, it uses an alert dialog box to notify you of the errors, preventing you from saving it as a draft.  Bloggers often write directly in the CMS and wish to work on a specifc piece over time, not all at once.  Nothing is worse than filling out a long form, and typing up a significant amount of content, to be left unable to save because you're missing a single item or don't want it to be published yet.

This problem can be resolved by modifying the JavaScript in "fields.inc.php" found on line 438 in "assets/plugins/managermanager/functions".  By using a confirm box rather than an alert message, you can specify whether or not the user can continue or go back to make the appropriate corrections.

At the bottom of the php file, you will find the following.

if(errors.length > 0){     

var errMsg = errors.length + " required fields are missing:\n\n ";
for (var i=0; i<errors.length; i++) {
errMsg += " - " + errors[i] + " \n";

}
errMsg += " \nPlease correct the indicated fields.";

alert(errMsg); 
return false; 
} else { 
return true;

By changing the alert to confirm and setting a variable, you're given the ability to bypass the error message.  For example:

if(errors.length > 0){ 

var errMsg = errors.length + " required fields are missing:\n\n ";
for (var i=0; i<errors.length; i++) {
errMsg +="- " + errors[i] + " \n";
}
errMsg += " \nPlease correct the indicated fields.\n\n Click OK to save to drafts, or cancel to make corrections.";


r=confirm(errMsg); 
if (r==true)  { 
return true; 
} else { 
return false; 
}

}

Now users are able to save, even if they're not done with the document yet.  It will still notify them the next time they go to update their draft as a reminder.  I've attached a modified fields.inc.php file for those who would like to update their ManagerManager Plugin.

Download Zip

Copyright © 2011 Garret Overstreet. All rights reserved. This material may not be published, broadcasted, rewritten or redistributed without an appropriate link to the original source.


Blogs

Most Popular
Related
Recent

Get Updates

Want to get more information?

* indicates required