Saving content state with contenteditable div

Forums: 

SOLVED: Another instance of me solving the problem five minutes after posting. I am developing on Drupal and was not logged in. I usually use a default admin account. I also wasn't checking that the responses array was created before trying to access it from the Object. :)

 

I am using the H5P-Question boilerplate, and was able to store the previous state with input field just fine.

 

this.getCurrentState = () => {
    const responses = [];
    for (let i = 0; i < this.params.questions.length; i++) {
        responses.push(document.getElementById(contentID + "_" + i).firstElementChild.value);
    }
    return { responses: responses };
};

 

Now we have replced vanilla input fields with contenteditable divs, but the state no longer stores where nothing else has changed except for the way to extract the inner text of the div. If I print the responses array, it is updating fine, but it is not being passed through the H5P backend properly. Is there some reason this isn't working?

 

this.getCurrentState = () => {
    const responses = [];
    for (let i = 0; i < this.params.questions.length; i++) {
        responses.push(document.getElementById(contentID + "_" + i).firstElementChild.textContent);
    }
    return { responses: responses };
};

 

BV52's picture

Hi edemattos,

I'm glad it is working for you now and if you have other questions feel free to post in the forums.

-BV