Here is a quick and not necessarily the most elegant solution. This is a
Firefox solution and won't work on
IE. With some googling you should be able to fill in the blanks and make it cross-browser. First the code:
<script type="text/javascript">
function validate(e){
var fld=document.getElementById('
XXXXX#id');
if (fld.value==''){
e.preventDefault();
alert('You must provide a value');
fld.focus();
return false;
}
}
var frm = document.getElementById('divForm').parentNode.parentNode.parentNode;
if (frm.addEventListener) frm.addEventListener('submit',validate,false);
</script>
Guidelines:
Enclose your current template code in a div tag with id 'divForm'.
Put the code at the end of the template (right after the close tag of 'divForm' you just added).
Change XXXXX to the desired field name.
Add other validations.
Try.
With some luck it will work.
Explanation:
The path '.parentNode.parentNode.parentNode' should return the form element which performs the submit when you save the entry. It is this submit that we want to capture and stop if the validation fails. Then we add a listener to capture the submit event. Upon save attempt the submit event is fired and the validate function is called. In the function the field to validate is retrieved, its value is checked and if not valid (empty in this example) the submit is canceled, a message is displayed and the focus is returned to that field.
I hope this helps.