Forumindlæg af Itamar Tzadok

If there are no newline and other such characters you can pass the value to a javascript function in the template.

<script>
function foo ('SONG')
</script>

Otherwise you can store the item in a hidden div and retrieve it from within the function:

<div id="divsong" style="display:none">SONG</div>
<script>
function foo (){
var song=document.getElementById('divsong').innerHTML;
...
}
</script>

The latter in the list template should use name rather than id:
header template:
<script>
var rec=0;
}
</script>

body template:
<div name="divsong" style="display:none">SONG</div>
<script>
function foo (){
var song=document.getElementsByName('divsong')[rec].innerHTML;
...
rec++;
}
</script>

I hope that helps. smiler

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. smiler


Yes, that's a good guess. Something I do in the add entry page is open a dialog window for writing some formatted stuff (special characters and other things). Closing that window copies the formatted text into a textarea field (Moodle editor) and also sets a radio button field. All that (and more) with javascript. smiler
Just an idea ... you can have two fields in the Add template one for the hack and the other for normal functionality. In each entry one of these fields will be empty: initially (abnormal functionality) the attachment field will be empty and when the entry is updated the name field should be clear. You set the display templates (list/single) to check which of these two field contains a value and to display the link in the appropriate method.

It is probably possible to set the attachment field in the Add page already when you upload the CSV. I will look into it next time I go into design mode/mood. smiler
Not sure I get the terminology right but isn't the legend of a radio button field the options you enter when you create it? So suppose you set the options with the labels you want for the legend. When you display the data you can convert those labels to corresponding display values. An alternative way is to add to the Add template some javascript and change the labels. That shouldn't be too difficult. smiler