Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Problem with ratingscale

Hi,

is there any way to group a variable for a checkbox and a rating scale? So that the participant can answer either with a point on the scale or by marking a checkbox. I also need to have a validator that checks that the participants have done one of these things. It works if I have a validator with the following code: "return var.var1 != 'no'" and var1 is the variable for both the rating scale and the checkbox(not adding a group for the checkbox). However, in this case, it's not possible to unselect the rating scale. This means that if the participant first click on a point on the scale and then wants to answer with the checkbox instead, it's not possible. (I'm using legacy and inline scripts).

Thanks in advance!

Comments

  • Hi Lina,

    That's an interesting scenario. So I guess you want have a checkbox that participants can check to indicate that they don't want to check anything on the rating scale. Right? Of course the most pragmatic solution would be to simply add one node to the rating scale, and label it 'Not applicable' or something like that.

    A more elaborate solution would be to validate the form on every click, and uncheck any nodes on the rating scale whenever the no-rating checkbox has been checked. That's possible, but it requires a bit of hacking, as you can see in the script below. (Personally I'd probably go with the easy option of adding a node to the rating scale!)

    Cheers,

    Sebastiaan

    def validate():
        
        # If the no-rating checkbox is checked, disallow any value to be set on
        # the rating scale
        if var.no_rating != 'no':
            rating_scale.set_value(None)
            rating_scale._update()
            form.render()
        print(var.no_rating, var.rating)
        # Only accept the form when the Ok button has been clicked
        return var.ok_button == 'yes'
        
    
    form = Form(validator=validate)
    # The .construct() is a hack that turns the widget into an object that
    # supports .set_value() etc.
    rating_scale = RatingScale(
        nodes=5,
        var='rating',
        click_accepts=True  # To call validate() on every click
    ).construct(form)
    checkbox = Checkbox(
        text='Don\'t rate',
        var='no_rating',
        click_accepts=True  # To call validate() on every click
    )
    button = Button(text='Ok', var='ok_button')
    form.set_widget(rating_scale, (0, 0))
    form.set_widget(checkbox, (1, 0))
    form.set_widget(button, (0, 1), colspan=2)
    form._exec()
    


    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Hi Sebastiaan,

    yes exactly! The reason for this question was that I wanted to add a "Don't want to answer" option. Thank you so much for your suggestions. I'll try both and see what works best for me.

    All the best,

    Lina

Sign In or Register to comment.