Created
November 15, 2013 04:21
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
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
@Steve - the above code seems to throw an error: http://pastebin.com/TW9Mmmkz