Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created November 15, 2013 04:21
Show Gist options
  • Save stevewithington/7479037 to your computer and use it in GitHub Desktop.
Save stevewithington/7479037 to your computer and use it in GitHub Desktop.
Mura CMS : This is an example of how to make the Summary field a required field. You could use this example to make pretty much any other field, including extended attributes, required as well.
<cfscript>
// Drop this in your Site or Theme eventHandler.cfc
public any function onBeforeContentSave($) {
// reference to the newBean
var newBean = arguments.$.event('newBean');
// reference to the original contentBean
var oldBean = arguments.$.event('contentBean');
// example on how to create some errors
var error = '';
var errors = {};
// Make Summary a required field
if ( !Len(newBean.getSummary()) ) {
StructAppend(errors, {'e1': 'Summary is required.'});
}
// if there's errors
if ( !StructIsEmpty(errors) ) {
for ( error in errors ) {
arguments.$.event('contentBean').getErrors()[error] = errors[error];
}
}
}
</cfscript>
@ronnieduke
Copy link

@Steve - the above code seems to throw an error: http://pastebin.com/TW9Mmmkz

@PeterBowater
Copy link

This appears to be Railo only, Coldfusion baulks for invalid syntax.

This will get you going on Coldfusion:

<cfscript>

        public any function onBeforePageNewsSave($) {
            var newBean = arguments.$.event('newBean');
            var oldBean = arguments.$.event('contentBean');
            var error = '';
            var errors = structNew();
            if ( !Len(newBean.getSummary()) ) {
              errors.e1 = 'Summary is required.';
            }
            if ( !StructIsEmpty(errors) ) {
                for ( error in errors ) {
                    arguments.$.event('contentBean').getErrors()[error] = errors[error];
                }
            }
        }
    </cfscript>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment