XML format of drag and drop input [inputtypes]

Format description

The main tag of Drag and Drop (DnD) input is:

<drag_and_drop_input> ... </drag_and_drop_input>

drag_and_drop_input can include any number of the following 2 tags: draggable and target.

drag_and_drop_input tag

The main container for a single instance of DnD. The following attributes can be specified for this tag:

img - Relative path to an image that will be the base image. All draggables
      can be dragged onto it.
target_outline - Specify whether an outline (gray dashed line) should be
      drawn around targets (if they are specified). It can be either
      'true' or 'false'. If not specified, the default value is
      'false'.
one_per_target - Specify whether to allow more than one draggable to be
      placed onto a single target. It can be either 'true' or 'false'. If
      not specified, the default value is 'true'.
no_labels - default is false, in default behaviour if label is not set, label
      is obtained from id. If no_labels is true, labels are not automatically
      populated from id, and one can not set labels and obtain only icons.

draggable tag

Draggable tag specifies a single draggable object which has the following attributes:

id - Unique identifier of the draggable object.
label - Human readable label that will be shown to the user.
icon - Relative path to an image that will be shown to the user.
can_reuse - true or false, default is false. If true, same draggable can be
used multiple times.

A draggable is what the user must drag out of the slider and place onto the base image. After a drag operation, if the center of the draggable ends up outside the rectangular dimensions of the image, it will be returned back to the slider.

In order for the grader to work, it is essential that a unique ID is provided. Otherwise, there will be no way to tell which draggable is at what coordinate, or over what target. Label and icon attributes are optional. If they are provided they will be used, otherwise, you can have an empty draggable. The path is relative to ‘course_folder’ folder, for example, /static/images/img1.png.

target tag

Target tag specifies a single target object which has the following required attributes:

id - Unique identifier of the target object.
x - X-coordinate on the base image where the top left corner of the target
    will be positioned.
y - Y-coordinate on the base image where the top left corner of the target
    will be positioned.
w - Width of the target.
h - Height of the target.

A target specifies a place on the base image where a draggable can be positioned. By design, if the center of a draggable lies within the target (i.e. in the rectangle defined by [[x, y], [x + w, y + h]], then it is within the target. Otherwise, it is outside.

If at lest one target is provided, the behavior of the client side logic changes. If a draggable is not dragged on to a target, it is returned back to the slider.

If no targets are provided, then a draggable can be dragged and placed anywhere on the base image.

Targets on draggables

Sometimes it is not enough to have targets only on the base image, and all of the draggables on these targets. If a complex problem exists where a draggable must become itself a target (or many targets), then the following extended syntax can be used:

<draggable {attribute list}>
    <target {attribute list} />
    <target {attribute list} />
    <target {attribute list} />
    ...
</draggable>

The attribute list in the tags above (‘draggable’ and ‘target’) is the same as for normal ‘draggable’ and ‘target’ tags. The only difference is when you will be specifying inner target position coordinates. Using the ‘x’ and ‘y’ attributes you are setting the offset of the inner target from the upper-left corner of the parent draggable (that contains the inner target).

Limitations of targets on draggables

1.) Currently there is a limitation to the level of nesting of targets.

Even though you can pile up a large number of draggables on targets that themselves are on draggables, the Drag and Drop instance will be graded only in the case if there is a maximum of two levels of targets. The first level are the “base” targets. They are attached to the base image. The second level are the targets defined on draggables.

2.) Another limitation is that the target bounds are not checked against other targets.

For now, it is the responsibility of the person who is constructing the course material to make sure that there is no overlapping of targets. It is also preferable that targets on draggables are smaller than the actual parent draggable. Technically this is not necessary, but from the usability perspective it is desirable.

3.) You can have targets on draggables only in the case when there are base targets defined (base targets are attached to the base image).

If you do not have base targets, then you can only have a single level of nesting (draggables on the base image). In this case the client side will be reporting (x,y) positions of each draggables on the base image.

Correct answer format

(NOTE: For specifying answers for targets on draggables please see next section.)

There are two correct answer formats: short and long If short from correct answer is mapping of ‘draggable_id’ to ‘target_id’:

correct_answer = {'grass':     [[300, 200], 200], 'ant': [[500, 0], 200]}
correct_answer = {'name4': 't1', '7': 't2'}

In long form correct answer is list of dicts. Every dict has 3 keys: draggables, targets and rule. For example:

correct_answer = [
{
'draggables':   ['7', '8'],
'targets':  ['t5_c', 't6_c'],
'rule': 'anyof'
},
{
'draggables': ['1', '2'],
'targets': ['t2_h', 't3_h', 't4_h', 't7_h', 't8_h', 't10_h'],
'rule': 'anyof'
}]

Draggables is list of draggables id. Target is list of targets id, draggables must be dragged to with considering rule. Rule is string.

Draggables in dicts inside correct_answer list must not intersect!!!

Wrong (for draggable id 7):

correct_answer = [
{
'draggables':   ['7', '8'],
'targets':  ['t5_c', 't6_c'],
'rule': 'anyof'
},
{
'draggables': ['7', '2'],
'targets': ['t2_h', 't3_h', 't4_h', 't7_h', 't8_h', 't10_h'],
'rule': 'anyof'
}]

Rules are: exact, anyof, unordered_equal, anyof+number, unordered_equal+number

  • Exact rule means that targets for draggable id’s in user_answer are the same that targets from correct answer. For example, for draggables 7 and 8 user must drag 7 to target1 and 8 to target2 if correct_answer is:

    correct_answer = [
    {
    'draggables':   ['7', '8'],
    'targets':  ['tartget1', 'target2'],
    'rule': 'exact'
    }]
    
  • unordered_equal rule allows draggables be dragged to targets unordered. If one want to allow for student to drag 7 to target1 or target2 and 8 to target2 or target 1 and 7 and 8 must be in different targets, then correct answer must be:

    correct_answer = [
    {
    'draggables':   ['7', '8'],
    'targets':  ['tartget1', 'target2'],
    'rule': 'unordered_equal'
    }]
    
  • Anyof rule allows draggables to be dragged to any of targets. If one want to allow for student to drag 7 and 8 to target1 or target2, which means that if 7 is on target1 and 8 is on target1 or 7 on target2 and 8 on target2 or 7 on target1 and 8 on target2. Any of theese are correct which anyof rule:

    correct_answer = [
    {
    'draggables':   ['7', '8'],
    'targets':  ['tartget1', 'target2'],
    'rule': 'anyof'
    }]
    
  • If you have can_reuse true, then you, for example, have draggables a,b,c and 10 targets. These will allow you to drag 4 ‘a’ draggables to [‘target1’, ‘target4’, ‘target7’, ‘target10’] , you do not need to write ‘a’ four times. Also this will allow you to drag ‘b’ draggable to target2 or target5 for target5 and target2 etc..:

    correct_answer = [
        {
            'draggables': ['a'],
            'targets': ['target1',  'target4', 'target7', 'target10'],
            'rule': 'unordered_equal'
        },
        {
            'draggables': ['b'],
            'targets': ['target2', 'target5', 'target8'],
            'rule': 'anyof'
        },
        {
            'draggables': ['c'],
            'targets': ['target3', 'target6', 'target9'],
            'rule': 'unordered_equal'
        }]
    
  • And sometimes you want to allow drag only two ‘b’ draggables, in these case you should use ‘anyof+number’ of ‘unordered_equal+number’ rule:

    correct_answer = [
        {
            'draggables': ['a', 'a', 'a'],
            'targets': ['target1',  'target4', 'target7'],
            'rule': 'unordered_equal+numbers'
        },
        {
            'draggables': ['b', 'b'],
            'targets': ['target2', 'target5', 'target8'],
            'rule': 'anyof+numbers'
        },
        {
            'draggables': ['c'],
            'targets': ['target3', 'target6', 'target9'],
            'rule': 'unordered_equal'
        }]
    

In case if we have no multiple draggables per targets (one_per_target=”true”), for same number of draggables, anyof is equal to unordered_equal

If we have can_reuse=true, than one must use only long form of correct answer.

Answer format for targets on draggables

As with the cases described above, an answer must provide precise positioning for each draggable (on which targets it must reside). In the case when a draggable must be placed on a target that itself is on a draggable, then the answer must contain the chain of target-draggable-target. It is best to understand this on an example.

Suppose we have three draggables - ‘up’, ‘s’, and ‘p’. Draggables ‘s’, and ‘p’ have targets on themselves. More specifically, ‘p’ has three targets - ‘1’, ‘2’, and ‘3’. The first requirement is that ‘s’, and ‘p’ are positioned on specific targets on the base image. The second requirement is that draggable ‘up’ is positioned on specific targets of draggable ‘p’. Below is an excerpt from a problem.:

<draggable id="up" icon="/static/images/images_list/lcao-mo/up.png" can_reuse="true" />

<draggable id="s" icon="/static/images/images_list/lcao-mo/orbital_single.png" label="s orbital" can_reuse="true" >
    <target id="1" x="0" y="0" w="32" h="32"/>
</draggable>

<draggable id="p" icon="/static/images/images_list/lcao-mo/orbital_triple.png" can_reuse="true" label="p orbital" >
    <target id="1" x="0" y="0" w="32" h="32"/>
    <target id="2" x="34" y="0" w="32" h="32"/>
    <target id="3" x="68" y="0" w="32" h="32"/>
</draggable>

...

correct_answer = [
    {
        'draggables': ['p'],
        'targets': ['p-left-target', 'p-right-target'],
        'rule': 'unordered_equal'
    },
    {
        'draggables': ['s'],
        'targets': ['s-left-target', 's-right-target'],
        'rule': 'unordered_equal'
    },
    {
        'draggables': ['up'],
        'targets': ['p-left-target[p][1]', 'p-left-target[p][2]', 'p-right-target[p][2]', 'p-right-target[p][3]',],
        'rule': 'unordered_equal'
    }
]

Note that it is a requirement to specify rules for all draggables, even if some draggable gets included in more than one chain.

Grading logic

  1. User answer (that comes from browser) and correct answer (from xml) are parsed to the same format:

    group_id: group_draggables, group_targets, group_rule

Group_id is ordinal number, for every dict in correct answer incremental group_id is assigned: 0, 1, 2, ...

Draggables from user answer are added to same group_id where identical draggables from correct answer are, for example:

If correct_draggables[group_0] = [t1, t2] then
user_draggables[group_0] are all draggables t1 and t2 from user answer:
[t1] or [t1, t2] or [t1, t2, t2] etc..

2. For every group from user answer, for that group draggables, if ‘number’ is in group rule, set() is applied, if ‘number’ is not in rule, set is not applied:

set() : [t1, t2, t3, t3] -> [t1, t2, ,t3]

For every group, at this step, draggables lists are equal.

  1. For every group, lists of targets are compared using rule for that group.

Set and ‘+number’ cases

Set() and ‘+number’ are needed only for case of reusable draggables, for other cases there are no equal draggables in list, so set() does nothing.

  • Usage of set() operation allows easily create rule for case of “any number of same draggable can be dragged to some targets”:

    {
            'draggables': ['draggable_1'],
            'targets': ['target3', 'target6', 'target9'],
            'rule': 'anyof'
    }
    
  • ‘number’ rule is used for the case of reusable draggables, when one want to fix number of draggable to drag. In this example only two instances of draggables_1 are allowed to be dragged:

    {
            'draggables': ['draggable_1', 'draggable_1'],
            'targets': ['target3', 'target6', 'target9'],
            'rule': 'anyof+number'
    }
    
  • Note, that in using rule ‘exact’, one does not need ‘number’, because you can’t recognize from user interface which reusable draggable is on which target. Absurd example:

    {
            'draggables': ['draggable_1', 'draggable_1', 'draggable_2'],
            'targets': ['target3', 'target6', 'target9'],
            'rule': 'exact'
    }
    
    
    Correct handling of this example is to create different rules for draggable_1 and
    draggable_2
  • For ‘unordered_equal’ (or ‘exact’ too) we don’t need ‘number’ if you have only same draggable in group, as targets length will provide constraint for the number of draggables:

    {
            'draggables': ['draggable_1'],
            'targets': ['target3', 'target6', 'target9'],
            'rule': 'unordered_equal'
    }
    
    
    This means that only three draggaggables 'draggable_1' can be dragged.
  • But if you have more that one different reusable draggable in list, you may use ‘number’ rule:

    {
            'draggables': ['draggable_1', 'draggable_1', 'draggable_2'],
            'targets': ['target3', 'target6', 'target9'],
            'rule': 'unordered_equal+number'
    }
    
    
    If not use number, draggables list will be setted to  ['draggable_1', 'draggable_2']

Logic flow

(Click on image to see full size version.)

../../_images/draganddrop_logic_flow.png

Example

Examples of draggables that can’t be reused

<problem display_name="Drag and drop demos: drag and drop icons or labels
    to proper positions." >

<customresponse>
    <text>
        <h4>[Anyof rule example]</h4><br/>
        <h4>Please label hydrogen  atoms connected with left carbon atom.</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/ethglycol.jpg" target_outline="true"
        one_per_target="true" no_labels="true" label_bg_color="rgb(222, 139, 238)">
        <draggable id="1" label="Hydrogen" />
        <draggable id="2" label="Hydrogen" />

        <target id="t1_o" x="10" y="67" w="100" h="100"/>
        <target id="t2" x="133" y="3" w="70" h="70"/>
        <target id="t3" x="2" y="384" w="70" h="70"/>
        <target id="t4" x="95" y="386" w="70" h="70"/>
        <target id="t5_c" x="94" y="293" w="91" h="91"/>
        <target id="t6_c" x="328" y="294" w="91" h="91"/>
        <target id="t7" x="393" y="463" w="70" h="70"/>
        <target id="t8" x="344" y="214" w="70" h="70"/>
        <target id="t9_o" x="445" y="162" w="100" h="100"/>
        <target id="t10" x="591" y="132" w="70" h="70"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{'draggables': ['1', '2'],
'targets': ['t2', 't3', 't4' ],
'rule':'anyof'
}]
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Complex grading example]</h4><br/>
        <h4>Describe carbon molecule in LCAO-MO.</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/lcao-mo/lcao-mo.jpg" target_outline="true" >

        <!-- filled bond -->
        <draggable id="1" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="2" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="3" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="4" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="5" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="6" icon="/static/images/images_list/lcao-mo/u_d.png" />

        <!-- up bond -->
        <draggable id="7"  icon="/static/images/images_list/lcao-mo/up.png"/>
        <draggable id="8"  icon="/static/images/images_list/lcao-mo/up.png"/>
        <draggable id="9"  icon="/static/images/images_list/lcao-mo/up.png"/>
        <draggable id="10" icon="/static/images/images_list/lcao-mo/up.png"/>

        <!-- sigma -->
        <draggable id="11" icon="/static/images/images_list/lcao-mo/sigma.png"/>
        <draggable id="12" icon="/static/images/images_list/lcao-mo/sigma.png"/>

        <!-- sigma* -->
        <draggable id="13" icon="/static/images/images_list/lcao-mo/sigma_s.png"/>
        <draggable id="14" icon="/static/images/images_list/lcao-mo/sigma_s.png"/>

        <!-- pi -->
        <draggable id="15" icon="/static/images/images_list/lcao-mo/pi.png" />

        <!-- pi* -->
        <draggable id="16" icon="/static/images/images_list/lcao-mo/pi_s.png" />

        <!-- images that should not be dragged -->
        <draggable id="17" icon="/static/images/images_list/lcao-mo/d.png" />
        <draggable id="18" icon="/static/images/images_list/lcao-mo/d.png" />

        <!-- positions of electrons and electron pairs -->
        <target id="s_left"       x="130" y="360"    w="32" h="32"/>
        <target id="s_right"      x="505" y="360"    w="32" h="32"/>
        <target id="s_sigma"      x="320" y="425"    w="32" h="32"/>
        <target id="s_sigma_star" x="320" y="290"    w="32" h="32"/>
        <target id="p_left_1"     x="80"  y="100"    w="32" h="32"/>
        <target id="p_left_2"     x="125" y="100"    w="32" h="32"/>
        <target id="p_left_3"     x="175" y="100"    w="32" h="32"/>
        <target id="p_right_1"    x="465" y="100"    w="32" h="32"/>
        <target id="p_right_2"    x="515" y="100"    w="32" h="32"/>
        <target id="p_right_3"    x="560" y="100"    w="32" h="32"/>
        <target id="p_pi_1"       x="290" y="220"    w="32" h="32"/>
        <target id="p_pi_2"       x="335" y="220"    w="32" h="32"/>
        <target id="p_sigma"      x="315" y="170"    w="32" h="32"/>
        <target id="p_pi_star_1"  x="290" y="40"     w="32" h="32"/>
        <target id="p_pi_star_2"  x="340" y="40"     w="32" h="32"/>
        <target id="p_sigma_star" x="315" y="0"      w="32" h="32"/>

        <!-- positions of names of energy levels -->
        <target id="s_sigma_name"      x="400" y="425"  w="32" h="32"/>
        <target id="s_sigma_star_name" x="400" y="290"  w="32" h="32"/>
        <target id="p_pi_name"         x="400" y="220"  w="32" h="32"/>
        <target id="p_sigma_name"      x="400" y="170"  w="32" h="32"/>
        <target id="p_pi_star_name"    x="400" y="40"   w="32" h="32"/>
        <target id="p_sigma_star_name" x="400" y="0"    w="32" h="32"/>

  </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
  'draggables': ['1', '2', '3', '4', '5', '6'],
  'targets': [
    's_left', 's_right', 's_sigma', 's_sigma_star', 'p_pi_1', 'p_pi_2'
  ],
  'rule': 'unordered_equal'
}, {
  'draggables': ['7','8', '9', '10'],
  'targets': ['p_left_1', 'p_left_2', 'p_right_1','p_right_2'],
  'rule': 'unordered_equal'
}, {
  'draggables': ['11', '12'],
  'targets': ['s_sigma_name', 'p_sigma_name'],
  'rule': 'unordered_equal'
}, {
  'draggables': ['13', '14'],
  'targets': ['s_sigma_star_name', 'p_sigma_star_name'],
  'rule': 'unordered_equal'
}, {
  'draggables': ['15'],
  'targets': ['p_pi_name'],
  'rule': 'unordered_equal'
}, {
  'draggables': ['16'],
  'targets': ['p_pi_star_name'],
  'rule': 'unordered_equal'
}]

if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Another complex grading example]</h4><br/>
        <h4>Describe oxygen molecule in LCAO-MO</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/lcao-mo/lcao-mo.jpg" target_outline="true" one_per_target="true">
        <!-- filled bond -->
        <draggable id="1" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="2" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="3" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="4" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="5" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="6" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="v_fb_1" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="v_fb_2" icon="/static/images/images_list/lcao-mo/u_d.png" />
        <draggable id="v_fb_3" icon="/static/images/images_list/lcao-mo/u_d.png" />

        <!-- up bond -->
        <draggable id="7"  icon="/static/images/images_list/lcao-mo/up.png"/>
        <draggable id="8"  icon="/static/images/images_list/lcao-mo/up.png"/>
        <draggable id="9"  icon="/static/images/images_list/lcao-mo/up.png"/>
        <draggable id="10" icon="/static/images/images_list/lcao-mo/up.png"/>
        <draggable id="v_ub_1" icon="/static/images/images_list/lcao-mo/up.png"/>
        <draggable id="v_ub_2" icon="/static/images/images_list/lcao-mo/up.png"/>

        <!-- sigma -->
        <draggable id="11" icon="/static/images/images_list/lcao-mo/sigma.png"/>
        <draggable id="12" icon="/static/images/images_list/lcao-mo/sigma.png"/>

        <!-- sigma* -->
        <draggable id="13" icon="/static/images/images_list/lcao-mo/sigma_s.png"/>
        <draggable id="14" icon="/static/images/images_list/lcao-mo/sigma_s.png"/>

        <!-- pi -->
        <draggable id="15" icon="/static/images/images_list/lcao-mo/pi.png" />

        <!-- pi* -->
        <draggable id="16" icon="/static/images/images_list/lcao-mo/pi_s.png" />

        <!-- images that should not be dragged -->
        <draggable id="17" icon="/static/images/images_list/lcao-mo/d.png" />
        <draggable id="18" icon="/static/images/images_list/lcao-mo/d.png" />

        <!-- positions of electrons and electron pairs -->
        <target id="s_left"       x="130" y="360"    w="32" h="32"/>
        <target id="s_right"      x="505" y="360"    w="32" h="32"/>
        <target id="s_sigma"      x="320" y="425"    w="32" h="32"/>
        <target id="s_sigma_star" x="320" y="290"   w="32" h="32"/>
        <target id="p_left_1"     x="80"  y="100"   w="32" h="32"/>
        <target id="p_left_2"     x="125" y="100"   w="32" h="32"/>
        <target id="p_left_3"     x="175" y="100"   w="32" h="32"/>
        <target id="p_right_1"    x="465" y="100"   w="32" h="32"/>
        <target id="p_right_2"    x="515" y="100"   w="32" h="32"/>
        <target id="p_right_3"    x="560" y="100"   w="32" h="32"/>
        <target id="p_pi_1"       x="290" y="220"  w="32" h="32"/>
        <target id="p_pi_2"       x="335" y="220"  w="32" h="32"/>
        <target id="p_sigma"      x="315" y="170"  w="32" h="32"/>
        <target id="p_pi_star_1"  x="290" y="40"  w="32" h="32"/>
        <target id="p_pi_star_2"  x="340" y="40"  w="32" h="32"/>
        <target id="p_sigma_star" x="315" y="0"  w="32" h="32"/>

        <!-- positions of names of energy levels -->
        <target id="s_sigma_name" x="400" y="425"  w="32" h="32"/>
        <target id="s_sigma_star_name" x="400" y="290"  w="32" h="32"/>
        <target id="p_pi_name" x="400" y="220"  w="32" h="32"/>
        <target id="p_pi_star_name" x="400" y="40"  w="32" h="32"/>
        <target id="p_sigma_name" x="400" y="170"  w="32" h="32"/>
        <target id="p_sigma_star_name" x="400" y="0"  w="32" h="32"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [{
  'draggables': ['1', '2', '3', '4', '5', '6', 'v_fb_1', 'v_fb_2', 'v_fb_3'],
  'targets': [
    's_left', 's_right', 's_sigma', 's_sigma_star', 'p_pi_1', 'p_pi_2',
    'p_sigma', 'p_left_1', 'p_right_3'
  ],
  'rule': 'anyof'
}, {
  'draggables': ['7', '8', '9', '10', 'v_ub_1', 'v_ub_2'],
  'targets': [
    'p_left_2', 'p_left_3', 'p_right_1', 'p_right_2', 'p_pi_star_1',
    'p_pi_star_2'
  ],
  'rule': 'anyof'
}, {
  'draggables': ['11', '12'],
  'targets': ['s_sigma_name', 'p_sigma_name'],
  'rule': 'anyof'
}, {
  'draggables': ['13', '14'],
  'targets': ['s_sigma_star_name', 'p_sigma_star_name'],
  'rule': 'anyof'
}, {
  'draggables': ['15'],
  'targets': ['p_pi_name'],
  'rule': 'anyof'
}, {
  'draggables': ['16'],
  'targets': ['p_pi_star_name'],
  'rule': 'anyof'
}]

if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']

]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Individual targets with outlines, One draggable per target]</h4><br/>
        <h4>
        Drag -Ant- to first position and -Star- to third position </h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/cow.png" target_outline="true">
        <draggable id="1" label="Label 1"/>
        <draggable id="name_with_icon" label="Ant" icon="/static/images/images_list/ant.jpg"/>
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" />
        <draggable id="5" label="Label2" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" />
        <draggable id="name_label_icon3" label="Grass" icon="/static/images/images_list/grass.jpg" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" />
        <draggable id="7" label="Label3" />

        <target id="t1" x="20" y="20" w="90" h="90"/>
        <target id="t2" x="300" y="100" w="90" h="90"/>
        <target id="t3" x="150" y="40" w="50" h="50"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = {'name_with_icon': 't1', 'name4': 't2'}
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[SMALL IMAGE,  Individual targets WITHOUT outlines, One draggable
            per target]</h4><br/>
        <h4>
            Move -Star- to the volcano opening, and -Label3- on to
            the right ear of the cow.
        </h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/cow3.png" target_outline="false">
        <draggable id="1" label="Label 1"/>
        <draggable id="name_with_icon" label="Ant" icon="/static/images/images_list/ant.jpg"/>
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" />
        <draggable id="5" label="Label2" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" />
        <draggable id="name_label_icon3" label="Grass" icon="/static/images/images_list/grass.jpg" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" />
        <draggable id="7" label="Label3" />

        <target id="t1" x="111" y="58" w="90" h="90"/>
        <target id="t2" x="212" y="90" w="90" h="90"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = {'name4': 't1',
                '7': 't2'}
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Many draggables per target]</h4><br/>
        <h4>Move -Star- and -Ant- to most left target
            and -Label3- and -Label2- to most right target.</h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/cow.png" target_outline="true" one_per_target="false">
        <draggable id="1" label="Label 1"/>
        <draggable id="name_with_icon" label="Ant" icon="/static/images/images_list/ant.jpg"/>
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" />
        <draggable id="5" label="Label2" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" />
        <draggable id="name_label_icon3" label="Grass" icon="/static/images/images_list/grass.jpg" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" />
        <draggable id="7" label="Label3" />

        <target id="t1" x="20" y="20" w="90" h="90"/>
        <target id="t2" x="300" y="100" w="90" h="90"/>
        <target id="t3" x="150" y="40" w="50" h="50"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = {'name4': 't1',
                'name_with_icon': 't1',
                '5': 't2',
                '7':'t2'}
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Draggables can be placed anywhere on base image]</h4><br/>
        <h4>
            Place -Grass- in the middle of the image and -Ant- in the
            right upper corner.</h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/cow.png" >
        <draggable id="1" label="Label 1"/>
        <draggable id="ant" label="Ant" icon="/static/images/images_list/ant.jpg"/>
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" />
        <draggable id="5" label="Label2" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" />
        <draggable id="grass" label="Grass" icon="/static/images/images_list/grass.jpg" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" />
        <draggable id="7" label="Label3" />

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = {'grass':     [[300, 200], 200],
                  'ant': [[500, 0], 200]}
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Another anyof example]</h4><br/>
        <h4>Please identify the Carbon and Oxygen atoms in the molecule.</h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/ethglycol.jpg" target_outline="true" one_per_target="true">
        <draggable id="l1_c" label="Carbon" />
        <draggable id="l2" label="Methane"/>
        <draggable id="l3_o" label="Oxygen" />
        <draggable id="l4" label="Calcium" />
        <draggable id="l5" label="Methane"/>
        <draggable id="l6" label="Calcium" />
        <draggable id="l7" label="Hydrogen" />
        <draggable id="l8_c" label="Carbon" />
        <draggable id="l9" label="Hydrogen" />
        <draggable id="l10_o" label="Oxygen" />

        <target id="t1_o" x="10" y="67" w="100" h="100"/>
        <target id="t2" x="133" y="3" w="70" h="70"/>
        <target id="t3" x="2" y="384" w="70" h="70"/>
        <target id="t4" x="95" y="386" w="70" h="70"/>
        <target id="t5_c" x="94" y="293" w="91" h="91"/>
        <target id="t6_c" x="328" y="294" w="91" h="91"/>
        <target id="t7" x="393" y="463" w="70" h="70"/>
        <target id="t8" x="344" y="214" w="70" h="70"/>
        <target id="t9_o" x="445" y="162" w="100" h="100"/>
        <target id="t10" x="591" y="132" w="70" h="70"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
    'draggables':  ['l3_o', 'l10_o'],
    'targets':  ['t1_o', 't9_o'],
    'rule': 'anyof'
},
{
    'draggables': ['l1_c','l8_c'],
    'targets': ['t5_c','t6_c'],
    'rule': 'anyof'
}
]
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Again another anyof example]</h4><br/>
        <h4>If the element appears in this molecule, drag the label onto it</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/ethglycol.jpg" target_outline="true"
        one_per_target="true" no_labels="true" label_bg_color="rgb(222, 139, 238)">
        <draggable id="1" label="Hydrogen" />
        <draggable id="2" label="Hydrogen" />
        <draggable id="3" label="Nytrogen" />
        <draggable id="4" label="Nytrogen" />
        <draggable id="5" label="Boron" />
        <draggable id="6" label="Boron" />
        <draggable id="7" label="Carbon" />
        <draggable id="8" label="Carbon" />

        <target id="t1_o" x="10" y="67" w="100" h="100"/>
        <target id="t2_h" x="133" y="3" w="70" h="70"/>
        <target id="t3_h" x="2" y="384" w="70" h="70"/>
        <target id="t4_h" x="95" y="386" w="70" h="70"/>
        <target id="t5_c" x="94" y="293" w="91" h="91"/>
        <target id="t6_c" x="328" y="294" w="91" h="91"/>
        <target id="t7_h" x="393" y="463" w="70" h="70"/>
        <target id="t8_h" x="344" y="214" w="70" h="70"/>
        <target id="t9_o" x="445" y="162" w="100" h="100"/>
        <target id="t10_h" x="591" y="132" w="70" h="70"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
    'draggables':   ['7', '8'],
    'targets':  ['t5_c', 't6_c'],
    'rule': 'anyof'
},
{
    'draggables': ['1', '2'],
    'targets': ['t2_h', 't3_h', 't4_h', 't7_h', 't8_h', 't10_h'],
    'rule': 'anyof'
}]
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Wrong base image url example]
        </h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/cow3_bad.png" target_outline="false">
        <draggable id="1" label="Label 1"/>
        <draggable id="name_with_icon" label="Ant" icon="/static/images/images_list/ant.jpg"/>
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" />
        <draggable id="5" label="Label2" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" />
        <draggable id="name_label_icon3" label="Grass" icon="/static/images/images_list/grass.jpg" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" />
        <draggable id="7" label="Label3" />

        <target id="t1" x="111" y="58" w="90" h="90"/>
        <target id="t2" x="212" y="90" w="90" h="90"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = {'name4': 't1',
                '7': 't2'}
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

</problem>

Draggables can be reused

<problem display_name="Drag and drop demos: drag and drop icons or labels
    to proper positions." >

<customresponse>
    <text>
        <h4>[Draggable is reusable example]</h4>
        <br/>
        <h4>Please label all hydrogen atoms.</h4>
        <br/>
    </text>

    <drag_and_drop_input
        img="/static/images/images_list/ethglycol.jpg"
        target_outline="true"
        one_per_target="true"
        no_labels="true"
        label_bg_color="rgb(222, 139, 238)"
    >
        <draggable id="1" label="Hydrogen" can_reuse='true' />

        <target id="t1_o" x="10" y="67" w="100" h="100" />
        <target id="t2" x="133" y="3" w="70" h="70" />
        <target id="t3" x="2" y="384" w="70" h="70" />
        <target id="t4" x="95" y="386" w="70" h="70" />
        <target id="t5_c" x="94" y="293" w="91" h="91" />
        <target id="t6_c" x="328" y="294" w="91" h="91" />
        <target id="t7" x="393" y="463" w="70" h="70" />
        <target id="t8" x="344" y="214" w="70" h="70" />
        <target id="t9_o" x="445" y="162" w="100" h="100" />
        <target id="t10" x="591" y="132" w="70" h="70" />
    </drag_and_drop_input>

    <answer type="loncapa/python">
    <![CDATA[
correct_answer = [{
    'draggables': ['1'],
    'targets': ['t2', 't3', 't4', 't7', 't8', 't10'],
    'rule': 'exact'
}]
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
    ]]>
    </answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Complex grading example]</h4><br/>
        <h4>Describe carbon molecule in LCAO-MO.</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/lcao-mo/lcao-mo.jpg" target_outline="true" >

        <!-- filled bond -->
        <draggable id="1" icon="/static/images/images_list/lcao-mo/u_d.png" can_reuse="true" />

        <!-- up bond -->
        <draggable id="7"  icon="/static/images/images_list/lcao-mo/up.png" can_reuse="true" />

        <!-- sigma -->
        <draggable id="11" icon="/static/images/images_list/lcao-mo/sigma.png" can_reuse="true" />

        <!-- sigma* -->
        <draggable id="13" icon="/static/images/images_list/lcao-mo/sigma_s.png" can_reuse="true" />

        <!-- pi -->
        <draggable id="15" icon="/static/images/images_list/lcao-mo/pi.png" can_reuse="true" />

        <!-- pi* -->
        <draggable id="16" icon="/static/images/images_list/lcao-mo/pi_s.png" can_reuse="true" />

        <!-- images that should not be dragged -->
        <draggable id="17" icon="/static/images/images_list/lcao-mo/d.png" can_reuse="true" />

        <!-- positions of electrons and electron pairs -->
        <target id="s_left"       x="130" y="360"    w="32" h="32"/>
        <target id="s_right"      x="505" y="360"    w="32" h="32"/>
        <target id="s_sigma"      x="320" y="425"    w="32" h="32"/>
        <target id="s_sigma_star" x="320" y="290"    w="32" h="32"/>
        <target id="p_left_1"     x="80"  y="100"    w="32" h="32"/>
        <target id="p_left_2"     x="125" y="100"    w="32" h="32"/>
        <target id="p_left_3"     x="175" y="100"    w="32" h="32"/>
        <target id="p_right_1"    x="465" y="100"    w="32" h="32"/>
        <target id="p_right_2"    x="515" y="100"    w="32" h="32"/>
        <target id="p_right_3"    x="560" y="100"    w="32" h="32"/>
        <target id="p_pi_1"       x="290" y="220"    w="32" h="32"/>
        <target id="p_pi_2"       x="335" y="220"    w="32" h="32"/>
        <target id="p_sigma"      x="315" y="170"    w="32" h="32"/>
        <target id="p_pi_star_1"  x="290" y="40"     w="32" h="32"/>
        <target id="p_pi_star_2"  x="340" y="40"     w="32" h="32"/>
        <target id="p_sigma_star" x="315" y="0"      w="32" h="32"/>

        <!-- positions of names of energy levels -->
        <target id="s_sigma_name"      x="400" y="425"  w="32" h="32"/>
        <target id="s_sigma_star_name" x="400" y="290"  w="32" h="32"/>
        <target id="p_pi_name"         x="400" y="220"  w="32" h="32"/>
        <target id="p_sigma_name"      x="400" y="170"  w="32" h="32"/>
        <target id="p_pi_star_name"    x="400" y="40"   w="32" h="32"/>
        <target id="p_sigma_star_name" x="400" y="0"    w="32" h="32"/>

  </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
  'draggables': ['1'],
  'targets': [
    's_left', 's_right', 's_sigma', 's_sigma_star', 'p_pi_1', 'p_pi_2'
  ],
  'rule': 'exact'
}, {
  'draggables': ['7'],
  'targets': ['p_left_1', 'p_left_2', 'p_right_1','p_right_2'],
  'rule': 'exact'
}, {
  'draggables': ['11'],
  'targets': ['s_sigma_name', 'p_sigma_name'],
  'rule': 'exact'
}, {
  'draggables': ['13'],
  'targets': ['s_sigma_star_name', 'p_sigma_star_name'],
  'rule': 'exact'
}, {
  'draggables': ['15'],
  'targets': ['p_pi_name'],
  'rule': 'exact'
}, {
  'draggables': ['16'],
  'targets': ['p_pi_star_name'],
  'rule': 'exact'
}]

if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Many draggables per target]</h4><br/>
        <h4>Move two Stars and three Ants to most left target
            and one Label3 and four Label2 to most right target.</h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/cow.png" target_outline="true" one_per_target="false">
        <draggable id="1" label="Label 1" can_reuse="true" />
        <draggable id="name_with_icon" label="Ant" icon="/static/images/images_list/ant.jpg" can_reuse="true" />
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" can_reuse="true" />
        <draggable id="5" label="Label2" can_reuse="true" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" can_reuse="true" />
        <draggable id="name_label_icon3" label="Grass" icon="/static/images/images_list/grass.jpg" can_reuse="true" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" can_reuse="true" />
        <draggable id="7" label="Label3" can_reuse="true" />

        <target id="t1" x="20" y="20" w="90" h="90"/>
        <target id="t2" x="300" y="100" w="90" h="90"/>
        <target id="t3" x="150" y="40" w="50" h="50"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
    'draggables': ['name4'],
    'targets': [
        't1', 't1'
    ],
    'rule': 'exact'
},
{
    'draggables': ['name_with_icon'],
    'targets': [
        't1', 't1', 't1'
    ],
    'rule': 'exact'
},
{
    'draggables': ['5'],
    'targets': [
        't2', 't2', 't2', 't2'
    ],
    'rule': 'exact'
},
{
    'draggables': ['7'],
    'targets': [
        't2'
    ],
    'rule': 'exact'
}
]
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Draggables can be placed anywhere on base image]</h4><br/>
        <h4>
            Place -Grass- in the middle of the image and -Ant- in the
            right upper corner.</h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/cow.png" >
        <draggable id="1" label="Label 1" can_reuse="true" />
        <draggable id="ant" label="Ant" icon="/static/images/images_list/ant.jpg" can_reuse="true" />
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" can_reuse="true" />
        <draggable id="5" label="Label2" can_reuse="true" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" can_reuse="true" />
        <draggable id="grass" label="Grass" icon="/static/images/images_list/grass.jpg" can_reuse="true" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" can_reuse="true" />
        <draggable id="7" label="Label3" can_reuse="true" />

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = {
    'grass': [[300, 200], 200],
    'ant': [[500, 0], 200]
}
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Another anyof example]</h4><br/>
        <h4>Please identify the Carbon and Oxygen atoms in the molecule.</h4><br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/ethglycol.jpg" target_outline="true" one_per_target="true">
        <draggable id="l1_c" label="Carbon" can_reuse="true" />
        <draggable id="l2" label="Methane" can_reuse="true" />
        <draggable id="l3_o" label="Oxygen" can_reuse="true" />
        <draggable id="l4" label="Calcium" can_reuse="true" />
        <draggable id="l7" label="Hydrogen" can_reuse="true" />

        <target id="t1_o" x="10" y="67" w="100" h="100"/>
        <target id="t2" x="133" y="3" w="70" h="70"/>
        <target id="t3" x="2" y="384" w="70" h="70"/>
        <target id="t4" x="95" y="386" w="70" h="70"/>
        <target id="t5_c" x="94" y="293" w="91" h="91"/>
        <target id="t6_c" x="328" y="294" w="91" h="91"/>
        <target id="t7" x="393" y="463" w="70" h="70"/>
        <target id="t8" x="344" y="214" w="70" h="70"/>
        <target id="t9_o" x="445" y="162" w="100" h="100"/>
        <target id="t10" x="591" y="132" w="70" h="70"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
    'draggables': ['l3_o'],
    'targets': ['t1_o', 't9_o'],
    'rule': 'exact'
},
{
    'draggables': ['l1_c'],
    'targets': ['t5_c', 't6_c'],
    'rule': 'exact'
}
]
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Exact number of draggables for a set of targets.]</h4><br/>
        <h4>Drag two Grass and one Star to first or second positions, and three Cloud to any of the three positions.</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/cow.png" target_outline="true" one_per_target="false">
        <draggable id="1" label="Label 1" can_reuse="true" />
        <draggable id="name_with_icon" label="Ant" icon="/static/images/images_list/ant.jpg" can_reuse="true" />
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" can_reuse="true" />
        <draggable id="5" label="Label2" can_reuse="true" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" can_reuse="true" />
        <draggable id="name_label_icon3" label="Grass" icon="/static/images/images_list/grass.jpg" can_reuse="true" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" can_reuse="true" />
        <draggable id="7" label="Label3" can_reuse="true" />

        <target id="t1" x="20" y="20" w="90" h="90"/>
        <target id="t2" x="300" y="100" w="90" h="90"/>
        <target id="t3" x="150" y="40" w="50" h="50"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
    'draggables': ['name_label_icon3', 'name_label_icon3'],
    'targets': ['t1', 't3'],
    'rule': 'unordered_equal+number'
},
{
    'draggables': ['name4'],
    'targets': ['t1', 't3'],
    'rule': 'anyof+number'
},
{
    'draggables': ['with_icon', 'with_icon', 'with_icon'],
    'targets': ['t1', 't2', 't3'],
    'rule': 'anyof+number'
}
]
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[As many as you like draggables for a set of targets.]</h4><br/>
        <h4>Drag some Grass to any of the targets, and some Stars to either first or last target.</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/cow.png" target_outline="true" one_per_target="false">
        <draggable id="1" label="Label 1" can_reuse="true" />
        <draggable id="name_with_icon" label="Ant" icon="/static/images/images_list/ant.jpg" can_reuse="true" />
        <draggable id="with_icon" label="Cloud" icon="/static/images/images_list/cloud.jpg" can_reuse="true" />
        <draggable id="5" label="Label2" can_reuse="true" />
        <draggable id="2" label="Drop" icon="/static/images/images_list/drop.jpg" can_reuse="true" />
        <draggable id="name_label_icon3" label="Grass" icon="/static/images/images_list/grass.jpg" can_reuse="true" />
        <draggable id="name4" label="Star" icon="/static/images/images_list/star.png" can_reuse="true" />
        <draggable id="7" label="Label3" can_reuse="true" />

        <target id="t1" x="20" y="20" w="90" h="90"/>
        <target id="t2" x="300" y="100" w="90" h="90"/>
        <target id="t3" x="150" y="40" w="50" h="50"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
    'draggables': ['name_label_icon3'],
    'targets': ['t1', 't2', 't3'],
    'rule': 'anyof'
},
{
    'draggables': ['name4'],
    'targets': ['t1', 't2'],
    'rule': 'anyof'
}
]
if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

</problem>

Examples of targets on draggables

<problem display_name="Drag and drop demos chem features: drag and drop icons or labels
    to proper positions." attempts="10">

<customresponse>
    <text>
        <h4>[Simple grading example: draggables on draggables]</h4><br/>
        <h4>Describe carbon molecule in LCAO-MO.</h4><br/>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/lcao-mo/lcao-mo.jpg" target_outline="true" >

        <!-- filled bond -->
        <draggable id="up_and_down" icon="/static/images/images_list/lcao-mo/u_d.png" can_reuse="true" />
        <!-- up bond -->
        <draggable id="up"  icon="/static/images/images_list/lcao-mo/up.png" can_reuse="true" />

        <draggable id="s" icon="/static/images/images_list/lcao-mo/orbital_single.png" label="s orbital" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
        </draggable>

        <draggable id="p" icon="/static/images/images_list/lcao-mo/orbital_triple.png" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
            <target id="2" x="34" y="0" w="32" h="32"/>
            <target id="3" x="68" y="0" w="32" h="32"/>
        </draggable>

        <!-- positions of electrons and electron pairs -->
        <target id="s_l" x="130" y="360" w="32" h="32"/>
        <target id="s_r" x="505" y="360" w="32" h="32"/>
        <target id="p_l" x="80"  y="100" w="100" h="32"/>
        <target id="p_r" x="465" y="100" w="100" h="32"/>

  </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
    {
        'draggables': ['p'],
        'targets': ['p_l', 'p_r'],
        'rule': 'unordered_equal'
    },
    {
        'draggables': ['s'],
        'targets': ['s_l', 's_r'],
        'rule': 'unordered_equal'
    },
    {
      'draggables': ['up_and_down'],
      'targets': [
        's_l[s][1]', 's_r[s][1]'
      ],
      'rule': 'unordered_equal'
    },
    {
      'draggables': ['up'],
      'targets': [
        'p_l[p][1]', 'p_l[p][3]', 'p_r[p][1]', 'p_r[p][3]'
      ],
      'rule': 'unordered_equal'
    }
]

if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Complex grading example: draggables on draggables]</h4><br/>
        <h4>Describe carbon molecule in LCAO-MO.</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/lcao-mo/lcao-mo-clean.jpg" target_outline="true" >

        <!-- filled bond -->
        <draggable id="up_and_down" icon="/static/images/images_list/lcao-mo/u_d.png" can_reuse="true" />
        <!-- up bond -->
        <draggable id="up" icon="/static/images/images_list/lcao-mo/up.png" can_reuse="true" />

        <!-- images that should not be dragged -->
        <draggable id="down" icon="/static/images/images_list/lcao-mo/d.png" can_reuse="true" />

        <draggable id="s" icon="/static/images/images_list/lcao-mo/orbital_single.png" label="s orbital" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
        </draggable>

        <draggable id="p" icon="/static/images/images_list/lcao-mo/orbital_triple.png" can_reuse="true" label="p orbital" >
            <target id="1" x="0" y="0" w="32" h="32"/>
            <target id="2" x="34" y="0" w="32" h="32"/>
            <target id="3" x="68" y="0" w="32" h="32"/>
        </draggable>

        <draggable id="s-sigma" icon="/static/images/images_list/lcao-mo/orbital_single.png" label="s-sigma orbital" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
        </draggable>

        <draggable id="s-sigma*" icon="/static/images/images_list/lcao-mo/orbital_single.png" label="s-sigma* orbital" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
        </draggable>

        <draggable id="p-pi" icon="/static/images/images_list/lcao-mo/orbital_double.png" label="p-pi orbital" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
            <target id="2" x="34" y="0" w="32" h="32"/>
        </draggable>

        <draggable id="p-sigma" icon="/static/images/images_list/lcao-mo/orbital_single.png" label="p-sigma orbital" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
        </draggable>

        <draggable id="p-pi*" icon="/static/images/images_list/lcao-mo/orbital_double.png" label="p-pi* orbital" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
            <target id="2" x="34" y="0" w="32" h="32"/>
        </draggable>

        <draggable id="p-sigma*" icon="/static/images/images_list/lcao-mo/orbital_single.png" label="p-sigma* orbital" can_reuse="true" >
            <target id="1" x="0" y="0" w="32" h="32"/>
        </draggable>

        <!-- positions of electrons and electron pairs -->
        <target id="s-left-target" x="130" y="360" w="32" h="32"/>
        <target id="s-right-target" x="505" y="360" w="32" h="32"/>
        <target id="s-sigma-target" x="315" y="425" w="32" h="32"/>
        <target id="s-sigma*-target" x="315" y="290" w="32" h="32"/>
        <target id="p-left-target" x="80"  y="100" w="100" h="32"/>
        <target id="p-right-target" x="480" y="100" w="100" h="32"/>
        <target id="p-pi-target" x="300" y="220" w="66" h="32"/>
        <target id="p-sigma-target" x="315" y="170" w="32" h="32"/>
        <target id="p-pi*-target" x="300" y="40" w="66" h="32"/>
        <target id="p-sigma*-target" x="315" y="0" w="32" h="32"/>

    </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{'draggables': ['p'], 'targets': ['p-left-target', 'p-right-target'], 'rule': 'unordered_equal'},
{'draggables': ['s'], 'targets': ['s-left-target', 's-right-target'], 'rule': 'unordered_equal'},
{'draggables': ['s-sigma'], 'targets': ['s-sigma-target'], 'rule': 'exact'},
{'draggables': ['s-sigma*'], 'targets': ['s-sigma*-target'], 'rule': 'exact'},
{'draggables': ['p-pi'], 'targets': ['p-pi-target'], 'rule': 'exact'},
{'draggables': ['p-sigma'], 'targets': ['p-sigma-target'], 'rule': 'exact'},
{'draggables': ['p-pi*'], 'targets': ['p-pi*-target'], 'rule': 'exact'},
{'draggables': ['p-sigma*'], 'targets': ['p-sigma*-target'], 'rule': 'exact'},
{
    'draggables': ['up_and_down'],
    'targets': ['s-left-target[s][1]', 's-right-target[s][1]', 's-sigma-target[s-sigma][1]', 's-sigma*-target[s-sigma*][1]', 'p-pi-target[p-pi][1]', 'p-pi-target[p-pi][2]'],
    'rule': 'unordered_equal'
},
{
    'draggables': ['up'],
    'targets': ['p-left-target[p][1]', 'p-left-target[p][2]', 'p-right-target[p][2]', 'p-right-target[p][3]',],
    'rule': 'unordered_equal'
}
]

if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

<customresponse>
    <text>
        <h4>[Complex grading example: no draggables on draggables]</h4><br/>
        <h4>Describe carbon molecule in LCAO-MO.</h4>
        <br/>
    </text>

    <drag_and_drop_input img="/static/images/images_list/lcao-mo/lcao-mo.jpg" target_outline="true">

        <!-- filled bond -->
        <draggable id="1" icon="/static/images/images_list/lcao-mo/u_d.png" can_reuse="true" />

        <!-- up bond -->
        <draggable id="7"  icon="/static/images/images_list/lcao-mo/up.png" can_reuse="true" />

        <!-- sigma -->
        <draggable id="11" icon="/static/images/images_list/lcao-mo/sigma.png" can_reuse="true" />

        <!-- sigma* -->
        <draggable id="13" icon="/static/images/images_list/lcao-mo/sigma_s.png" can_reuse="true" />

        <!-- pi -->
        <draggable id="15" icon="/static/images/images_list/lcao-mo/pi.png" can_reuse="true" />

        <!-- pi* -->
        <draggable id="16" icon="/static/images/images_list/lcao-mo/pi_s.png" can_reuse="true" />

        <!-- images that should not be dragged -->
        <draggable id="17" icon="/static/images/images_list/lcao-mo/d.png" can_reuse="true" />

        <!-- positions of electrons and electron pairs -->
        <target id="s_left"       x="130" y="360"    w="32" h="32"/>
        <target id="s_right"      x="505" y="360"    w="32" h="32"/>
        <target id="s_sigma"      x="320" y="425"    w="32" h="32"/>
        <target id="s_sigma_star" x="320" y="290"    w="32" h="32"/>
        <target id="p_left_1"     x="80"  y="100"    w="32" h="32"/>
        <target id="p_left_2"     x="125" y="100"    w="32" h="32"/>
        <target id="p_left_3"     x="175" y="100"    w="32" h="32"/>
        <target id="p_right_1"    x="465" y="100"    w="32" h="32"/>
        <target id="p_right_2"    x="515" y="100"    w="32" h="32"/>
        <target id="p_right_3"    x="560" y="100"    w="32" h="32"/>
        <target id="p_pi_1"       x="290" y="220"    w="32" h="32"/>
        <target id="p_pi_2"       x="335" y="220"    w="32" h="32"/>
        <target id="p_sigma"      x="315" y="170"    w="32" h="32"/>
        <target id="p_pi_star_1"  x="290" y="40"     w="32" h="32"/>
        <target id="p_pi_star_2"  x="340" y="40"     w="32" h="32"/>
        <target id="p_sigma_star" x="315" y="0"      w="32" h="32"/>

        <!-- positions of names of energy levels -->
        <target id="s_sigma_name"      x="400" y="425"  w="32" h="32"/>
        <target id="s_sigma_star_name" x="400" y="290"  w="32" h="32"/>
        <target id="p_pi_name"         x="400" y="220"  w="32" h="32"/>
        <target id="p_sigma_name"      x="400" y="170"  w="32" h="32"/>
        <target id="p_pi_star_name"    x="400" y="40"   w="32" h="32"/>
        <target id="p_sigma_star_name" x="400" y="0"    w="32" h="32"/>

  </drag_and_drop_input>

    <answer type="loncapa/python"><![CDATA[
correct_answer = [
{
  'draggables': ['1'],
  'targets': [
    's_left', 's_right', 's_sigma', 's_sigma_star', 'p_pi_1', 'p_pi_2'
  ],
  'rule': 'exact'
}, {
  'draggables': ['7'],
  'targets': ['p_left_1', 'p_left_2', 'p_right_2','p_right_3'],
  'rule': 'exact'
}, {
  'draggables': ['11'],
  'targets': ['s_sigma_name', 'p_sigma_name'],
  'rule': 'exact'
}, {
  'draggables': ['13'],
  'targets': ['s_sigma_star_name', 'p_sigma_star_name'],
  'rule': 'exact'
}, {
  'draggables': ['15'],
  'targets': ['p_pi_name'],
  'rule': 'exact'
}, {
  'draggables': ['16'],
  'targets': ['p_pi_star_name'],
  'rule': 'exact'
}]

if draganddrop.grade(submission[0], correct_answer):
    correct = ['correct']
else:
    correct = ['incorrect']
]]></answer>
</customresponse>

</problem>