amp-up-io / qti3-item-player

The qti3-item-player component ("QTI 3 Player") is a 100% JavaScript component that aims to encapsulate the best practices and behaviors of the IMS Global QTI 3 Assessment Item specification.
https://qti.amp-up.io/#about
MIT License
16 stars 3 forks source link

QTI Simple Choice Interation #5

Open Panchiwalayash opened 2 days ago

Panchiwalayash commented 2 days ago

When selecting an option for questions in the application, I need the answer to be automatically checked. However, I am unable to find an event emitter that triggers when an option is changed, which is causing issues with automating the answer-checking process.

paulgrudnitski commented 2 days ago

Perhaps I am not understanding your requirement.

In QtiSimpleChoice there are 'click' and 'keydown' event handlers which trigger 'setChecked' events on the parent component (ChoiceGroup). Example:

handleClick () {
    if (this.isDisabled) return

    if (this.isRadio) {
        this.$parent.$emit('setChecked', { 'identifier': this.identifier, 'checked': 'true' })
    } else {
        this.toggleChecked()
        this.$parent.$emit('setChecked', { 'identifier': this.identifier, 'checked': this.checked })
    }
}

The $parent in this case is ChoiceGroup. And in QtiChoiceInteraction we can see that ChoiceGroup has an event handler for @setChecked

    <ChoiceGroup
      ref="choicegroup"
      :cardinality="cardinality"
      :shuffle="shuffle"
      :responseIdentifier="responseIdentifier"
      :maxChoices="maxChoices"
      :minChoices="minChoices"
      @choiceGroupReady="handleChoiceGroupReady"
      @setChecked="handleSetChecked"
      @setFocusNextChoice="handleSetFocusNextChoice"
      @setFocusPreviousChoice="handleSetFocusPreviousChoice"
      @setActiveDescendant="handleSetActiveDescendant"
      v-bind="$attrs">
      <slot name="default" />
    </ChoiceGroup>

In turn, 'handleSetChecked' receives the 'setChecked' event from the inner QtiSimpleChoice component before updating the interaction's response, validity, and state. From what I can interpret from the issue, 'handleSetChecked' in QtiChoiceInteraction seems to be the event handler you might be looking for.