Itamar Tzadok的帖子

Yes, you need to add fields. For this example you can add 4 menu fields:

Categories

The example assumes 3 options. the default 'Choose' will display none of the sub menus. The first options will display the Cars menu. The second option will display the Planes manu. The third will display the Planes and Ships menus. This is defined in the menudependcies array in the JS tab and you can change that definition to display the menus differently as desired. Note that that you can put anything you want in the option labels.

Cars

With some options.

Planes

With some options.

Ships

With some options.


The add template can look something like the following:

<div id="addtemplate">
<div id="category">Categories: [ [Categories]]</div>
<div id="cars">Cars: [ [Cars]]</div>
<div id="planes">Planes: [ [Planes]]</div>
<div id="ships">Ships: [ [Ships]]</div>
</div>

<script>
   // Set the onchange event of the category menu.
   var category = document.getElementById('[ [Categories#id]]');
   category.onchange = function() {showHideSubmenus(this.selectedIndex);};
   showHideSubmenus(category.selectedIndex);
</script>

(If you copy this code you need to remove the redundant spaces between square brackets)

hth 微笑

It was really just a stub. A working example could look something like the following.

In the JS tab:

var submenus = ['cars', 'planes', 'ships'];
var menudependencies = [
[],
['cars'],
['planes'],
['planes', 'ships']
];

function showHideSubmenus(index) {
// Hide the sub menus.
for (var h in submenus) {
document.getElementById(submenus[h]).style.display = 'none';
}

// Show the selected sub menus.
for (var s in menudependencies[index]) {
document.getElementById(menudependencies[index][s]).style.display = 'block';
}
}

The submenus is a list of element ids of div wrappers for the fields in the add template. The idea is to wrap the field pattern with an identified container element. In the template it would be something like: <div id="cars">[ [Cars] ]</div>.  Then for hide/show we don't need to worry about the actual id of the field element and simply hide/show the wrapper. This also allow us to put most of the javascript in the JS tab rather than in the template.

The list of menu dependencies simply defines for each index of the main menu which sub menus should be displayed.

The showHideSubmenus is the event handler. It first hides all the submenus and then shows only those which are defined in the dependencies for the given index.

All the sub menus are hidden by default via css in the CSS tab.

#cars, #planes, #ships { display: none; }

In the add template we assign the event handler to the onchange event of the main menu. We also call the eventhandler directly so that an existing selection would be applied when opening the entry for editing.

<script>
// Set the onchange event of the category menu.
var category = document.getElementById('Categories#id');
category.onchange = function() {showHideSubmenus(this.selectedIndex);};
showHideSubmenus(category.selectedIndex);
</script>


The approach hiding/showing wrappers rather than specific fields can have an interesting application. If you have an entry with many fields that are organized in sections, you can use a menu field to show one section at a time, and make the entering of content more manageable.


微笑

You can simplify a bit the javascript by defining the dependencies in an array and then iterating the array as needed. for example:

var submenus = ['more', 'menu1', 'menu2', 'menu3'];
var mainmenu = [
[],
['more', 'menu1'],
['more', 'menu2'],
['more', 'menu3']
];
function showHideSubmenus(mainmenu, submenus, index) {
for (var h in submenus) {
// hide element submenu[h].
}
for (var s in mainmenu[index]) {
// show element mainmenu[index][s].
}
}

hth 微笑

If you can use contributed plugins, you can try the Dataform module. You can do all kinds of grading there in different ways. You can add different types of content to accompany what you grade. You can set automated grading for different purposes. And so on. The module has a learning curve though. If you want to give it a try and have questions, you can post them in the Dataform forum.

If you can only use standard modules, you may be able to construct some types of graded non-assignment instances with the Database module.

hth 微笑

Most of the gifted students I have encountered were gifted primarily because they were doing considerable work including repetition at home, well before coming to the lecture (or rather not coming) or taking a test. They "self-punish", so to speak, and don't need others to do it for them. 微笑