Created
April 2, 2015 13:58
-
-
Save wezell/01b751637cd76ba87818 to your computer and use it in GitHub Desktop.
Simple custom field example
This file contains 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
## This example uses a custom field that is called "test" and has the variable name "test" | |
## first we get the content (we have access to all our | |
## velocity tools, including any custom ones that have been written | |
#set($content = $dotcontent.find($request.getParameter("inode"))) | |
## then we write some ugly js to get and set the values on the edit content form - | |
## the dom.id of the hidden field that stores the value is just the velocity variable name | |
## so watch out for js variable scope issues | |
<script> | |
function myButtonClick(){ | |
var x = document.getElementById('test').value; | |
if(x==undefined || x.length==0){ | |
x=0; | |
} | |
else{ | |
x=parseInt(x)+1; | |
} | |
document.getElementById('test').value=x; | |
document.getElementById('customValue').innerHTML=x; | |
} | |
</script> | |
## then we write out our user controls, displaying the value stored in the content object by default | |
## with a button (dojo styled) that calls our js | |
Custom Value: <span id="customValue">$!content.test</span> | |
<button dojoType="dijit.form.Button" id="myButton" onclick="myButtonClick">Click me!</button> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment