Hallo liebes Forum,
ich habe auf der Suche nach einer Lösung für mein Problem bereits Joffms Tutorial 2 gelesen und kann es nur wärmstens empfehlen. Echt super.
@Joffm: tausend Dank für die Arbeit!
Mein aktuellen Problme setzt sich aus mehreren Teilen zusammen:
1. Ich möchte eine Mehrfachantwort mit Kommantarfeldern erstellen.
2. Die Antwortmöglichkeiten sollen rotieren.
3. Eine Antwortmöglichkeit soll dabei aber immer am Ende stehen.
4. Und ich möchte einige Kommentarfelder ausbelnden.
Einzeln finde ich für jeden der 4 Teile eine Lösung, besonders mit Hilfe des o.g. Tutorials von Joffm ist das kein Problem.
Die Schwierigkeit besteht nun darin, die Kommentarfelder der ROTIERENDEN Antworten immer korrekt auszublenden.
Ich habe insgesamt 13 Antwortmöglichkeiten, wobei ich nur für das 2. und das 13. ein Kommentarfeld angezeigt bekommen möchte. Das 2. Item rotiert allerdings, das 13. soll stets auch an letzter Stelle stehen.
In Anlehnung an Joffms Tutorial habe ich nun folgendes in den Frage-Quelltext geschrieben:
---
$(document).on('ready pjax:scriptcomplete',function(){
// The number of answers to be fixed at the end of the list
var fixedAnswers = 13;
// Set this to "true" if you want "Other" to be fixed in the last position
var otherFixed = false;
// Identify this question
var qID = {9510};
// Find the number of answers
var ansCount = $('#question'+qID+' .answer-item').length;
if($('#question'+qID+' input[type="text"]').length > 0) {
ansCount = ansCount -1
}
console.log(ansCount);
// Place the last n answers created at the end of the list
var fixedIndex = fixedAnswers - 1;
for (var i=0; i<fixedAnswers; i++) {
var answer = $('input[id^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
var answerItem = $(answer).closest('.answer-item');
var answersList = $(answer).closest('ul');
$(answersList).append(answerItem);
fixedIndex--;
}
// Handle "Other"
if(otherFixed == true && $('#question'+qID+' input[type="text"]').length > 0) {
var otherAnswer = $('#question'+qID+' input[type="text"]');
var otherAnswerItem = $(otherAnswer ).closest('.answer-item');
var otherAnswersList = $(otherAnswer ).closest('ul');
$(otherAnswersList).append(otherAnswerItem);
}
});
</script><script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var thisQuestion = $('#question{9510}');
// Remove some text inputs
$('.checkbox-text-item:checkbox-text-item:eq(0) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(2) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(3) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(4) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(5) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(6) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(7) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(
![8) 8)](/media/kunena/emoticons/2.png)
.comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(9) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(10) .comment-item', thisQuestion).remove();
$('.checkbox-text-item:checkbox-text-item:eq(11) .comment-item', thisQuestion).remove();
});
</script>
---
Der erste Teil zum Fixieren des letzen Items funktioniert super. Das Problem besteht darin, dass dich der zweite Teil (das Ausblenden der Kommentarfelder) auf die fixe Position des jeweiligen Items bezieht. D.h. Es werden auch immer nur die beiden Kommentarfelder an 2. und 13. Position angezeigt. Leider rotieren ja aber die Antwort-Items dazu, sodass es nicht mehr funktioniert.
Ich vermute, ich müsste "einfach" den Bezug, der jetzt noch '.checkbox-text-item:checkbox-text-item:eq(11) .comment-item' heißt, ändern, sodass er sich nicht auf die Position des Items, sondern auf den (Antwort-)Code des Items bezieht.
Und genau da stoße ich wieder einmal an meine Grenzen
Ob mir da wohl jemand helfen kann?
Vielen lieben Dank schon einmal im Voraus.
Beste Grüße
Nessias