Retrieve Question Labels through SmartDOMDocument?

More
2 weeks 2 days ago #206680 by sodiumchl
Is there anyway to retrieve question labels this way? I tried "questions" and "labels" but could not get it to work.
$dom = new \toolsDomDocument\SmartDOMDocument();
                        $dom->loadPartialHTML($this->event->get('questions'));
                        $sLableId="ls-question-text-{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}";
                        $input=$dom->getElementById($sLabelId);

Please Log in to join the conversation.

LimeSurvey Partners
More
2 weeks 2 days ago #206688 by DenisChenu
getElementById : you get the id, not the label …

"ls-question-text-{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}" : where did you find this id ? I don't think it exist anywhre.

Sorry : but you have to learn www.php.net/manual/en/class.domdocument.php

Here $labels = getElementsByTagName('label');
foreach $labels as label : check attribute "for" answerSGQA

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

More
2 weeks 1 day ago - 2 weeks 1 day ago #206740 by sodiumchl
- "ls-question-text-{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}" : where did you find this id ? I don't think it exist anywhre.

I got it from inspecting a "Long Free Text" question, in LS v3 as below.

//type T
<div class=" question-text ">
<div id="ls-question-text-666477X2X24" class=" ls-label-question ">
My Long Free Text
</div>
</div>

<div class="ls-answers answer-item text-item ">
<textarea class="form-control " name="666477X2X24" id="answer666477X2X24"
rows="5" aria-labelledby="ls-question-text-666477X2X24"></textarea>
</div>

I would like to read/change the text "My Long Free Text" in beforeQuestionRender(). It seems toolsDomDocument should be able to do that. But what should I use in place of 'xxxxxxx' below? If you could point me to the documentation of event->get and event->set, I would greatly appreciate it.
$dom = new \toolsDomDocument\SmartDOMDocument();
$dom->loadPartialHTML($this->event->get('xxxxxxx'));
$sLableId="ls-question-text-{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}";
$input=$dom->getElementById($sLabelId);
Last edit: 2 weeks 1 day ago by sodiumchl.

Please Log in to join the conversation.

More
2 weeks 1 day ago #206741 by DenisChenu
But : it's 2 different part here : ls-question-text-666477X2X24 are not part of ANSWERS in the event …

See: github.com/LimeSurvey/LimeSurvey/blob/ma...on_text_content.twig
It came from theme.

And here : it's not label tag.
See event doc : manual.limesurvey.org/BeforeQuestionRender
The event allow you to update
- aQuestion.text ( My Long Free Text)
- aQuestion.answer (<textarea … >)
- ....

maybe best is to exlain what do you want to do ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now