%begin bug in custom forms?


(Lewis) #1

This code only ever prints “This answer is correct.”. Any ideas?

%begin_response_371443_q1%
    %begin_question_error_371443_q1^charcount:gt:0:1%
        <p>This answer is incorrect.</p>
    %else_question%
        <p>This answer is correct.</p>
    %end_question%
%end_response%

Using %begin_question_error_371443_q1^charcount:gt:0:1% outside of this block works but inside it doesn’t. I mean, it’s working but only ever branches to ‘This answer is correct’.


(Bart Banda) #2

Looks like you are mixing up a ^ with a : in the second nested begin statement.
Try something like this perhaps:

%begin_response_371443_q1%
    %begin_question_error_371443_q1^charcount^gt:0%
        <p>This answer is incorrect.</p>
    %else_question%
        <p>This answer is correct.</p>
    %end_question%
%end_response%

(Lewis) #3

Hi @Bart. Thanks for getting back to me!

Unfortunately, that hasn’t worked. I’ve even added ‘1’ to the end of ‘^charcount^gt:0’ to ensure it returns true if there’s an error message but the form still only ever prints ‘This answer is correct’.

Weird - it’s evaluating the outer IF, THEN, ELSE and it’s kinda evaluating the inner one too but not to the point where the %being_question_error_371443_q1_charcount^gt:0% is returning anything other than false every time.

This came about because of W3C’s recommendation that both form errors and correct answers should be relayed to the user inline with accessibility.


(Lewis) #4

Again, isolating and removing the inner code to outside the block works - I’m getting both repsonses @Bart .

%begin_question_error_371443_q1^charcount^gt:0:1%
        <p>This answer is incorrect.</p>
    %else_question%
        <p>This answer is correct.</p>
    %end_question%

(Lewis) #5

Inverting the code produces the right results - putting the error check outside and response check inside @Bart

 %begin_question_error_371443_q1^charcount^gt:0:1%
        <p>This answer is incorrect.</p>
    %else_question%
        %begin_response_371443_q1%
            <p>This answer is correct.</p>
        %end_response%
    %end_question%

(Bart Banda) #6

Hmm, interesting… What version of Matrix are you using?

Can you change this to SSJS to handle the show/hide logic? Might be easier?

But just to confirm when you say

Inverting the code produces the right results - putting the error check outside and response check inside

Do you mean it’s working now as the way you want it to?


#7

It may not be necessary to check for the error message length. A condition is true if the keyword is not empty. Could be rewritten as follows:

%begin_response_371443_q1%
  %begin_question_error_371443_q1%
    <p>This answer is incorrect.</p>
  %else_question%
    <p>This answer is correct.</p>
  %end_question%
%end_response%

(Lewis) #8

Hi @Bart. Thanks for the reply!

Yes, it’s working now, weirdly. Strange how it doesn’t seem to handle the nested IF, THEN … ELSE when it’s a check for an error message in this case :thinking:


(Lewis) #9

Hi @np81. I’ve got a memory like a sieve but I think I tried this approach. I don’t think I had much luck with it though. Have you tried it in Squiz? What version are you on?


#10

@lewis I tested on v6.9.1 - worked as expected.


(Lewis) #11

Ah, we’re a bit behind the times - v5.5 @np81