oTree Forum >

Help on Likert Scale

#1 by april30

Hi,

So I am trying to make likert scale in my survey.And I followed codes here https://otree.readthedocs.io/en/latest/forms.html#example-radio-buttons-in-tables-and-other-custom-layouts 

def make_field(label):
    return models.IntegerField(
        choices=[
                [1,'Strongly agree'],
                [2, 'agree'],
                [3, 'agree a little'],
                [4, 'neutral'],
                [5, 'disagree a little'],
                [6, 'Disagree'],
                [7, 'Strongly Disagree'],
        ],
        label=label,
        widget=widgets.RadioSelect,
    )


class Player(BasePlayer):
    peq1 = make_field('label question 1  ')
    
 and then include the following part in the html. But I keep getting the message " TypeError: 'IntegerField' object is not iterable" Anyone know what's going on?
 
 <table class="table">
    {{ for field in form }}
        <tr>
            <th>{{ field.label }}</th>
            {{ for choice in field }}
                <td>{{ choice }}</td>
            {{ endfor }}
        </tr>
    {{ endfor }}
</table>

#2 by swordchen

Hi,
I meet the same question, I figure it out by setting 'choices' as the code here(https://otree.readthedocs.io/en/latest/forms.html#example-radio-buttons-in-tables-and-other-custom-layouts).
choices=[1,2,3] instead of choices=[[1,'1'],[2,'2']```]. 
The choice label is pre-writeen in the html table as the following goes. The 1 2 3 4 5 will be shown as the column name in the first row of the table. You may try to replace 1 with strongly agree. 

<table class="table">
    <tr>
        <td>Question</td>
            <td>1(strongly agree)</td>  
            <td>2</td>
            <td>3</td>
            <td>4</td>
            <td>5</td>
        </tr>
    {{ for field in form }}
        <tr>
            <th>{{ field.label }}</th>
            {{ for choice in field }}
                <td>{{ choice }}</td>
            {{ endfor }}
        </tr>
    {{ endfor }}
</table>

Chen

Write a reply

Set forum username