Dependent fields with two or more criteria
Dependent fields with two or more criteria
musicaways
Posts: 5Questions: 3Answers: 0
Hello guys.
I would like to modify the fields in a form (show / hide) according to the value selected in a select field that has three values.
This process has to be done with three different criteria depending on the selected value.
Return the code I used, can you help me to figure out where I am wrong?
Thanks a lot.
editor.dependent( 'options', function ( val ) {
return val === 'Simple' ?
{ hide: ['1', '2', '3', '4', '5','6','7','8'] } :
{ show: [] };
return val === 'Simple2' ?
{ hide: ['5', '6', '7', '8'] } :
{ show: ['1', '2', '3', '4'] };
return val === 'Simple3' ?
{ hide: ['1', '2', '3', '4'] } :
{ show: ['5', '6', '7', '8'] };
} );
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Lines 5-10 are never reached. Lines 2 says 'if val is 'Simple' do line 3, otherwise do line 4, it then returns the val so it can never reach llines 5+. 'Simple2' and 'Simple3' they would be caught by line 4 because they don't match the first test and evaluate to the last clause of the ternary operator.
You'll need to change your logic so you can check for your other cases before returning.
Hi musicaways, maybe like this
Shay
Thank you very much Rob Brun, works great!
Hi musicways, I am glad that solution worked for you. If you would be so kind please mark my answer :-D
It wasn't asked as a question originally, but rather as a discussion, so it can't be marked with an accepted answer I'm afraid.
Allan
Oh, I see :-(
OOO - I've just discovered I can change them! I've just done that and marked your reply as the answer.
Allan
Radical! thank you Allan :-D
Shay