Dependent fields - show/hide + editor.field('').val()
Dependent fields - show/hide + editor.field('').val()
carrarachristophe
Posts: 113Questions: 25Answers: 2
Hello,
Based on that example, I am hidding/showing some fields based on a radio button. It works fine.
But In addition to showing/hidding some fields, I need to set the value of an hidden field to 0, or 1.
How can I add:
editor.field( 'bibliotheque_bibliotheques.possession').val(1);
in case val !== '1'
and add
editor.field( 'bibliotheque_bibliotheques.possession').val(0);
in case val === '1'
editor.dependent( 'bibliotheque_bibliotheques.voeux', function ( val ) {
return val === '1' ?
{ hide: ['bibliotheque_bibliotheques.date_achat', 'bibliotheque_bibliotheques.prix_achat', 'bibliotheque_bibliotheques.neuf'] } :
{ show: ['bibliotheque_bibliotheques.date_achat', 'bibliotheque_bibliotheques.prix_achat', 'bibliotheque_bibliotheques.neuf'] }
} );
I don't find any example of that.
Thanks and regards,
Christophe
This question has an accepted answers - jump to answer
Answers
It would be easier to add that combined functionality into a function, something like:
Colin
As simple as that...
Thank you Colin, it worked like a charm.
Hello,
I refer to the above.
I was wondering how I could replace
by something like:
How can I change the value of the field by computing the value of another one?
field().val()
can be both a getter and a setter, so you could have:That should do the trick!
Colin
Hi Colin,
Thank you for your prompt feed-back.
I am getting:
[object Object]1
When I change the code to:
I am getting (in case we have for example 'bibliotheque_bibliotheques.voeux'=12345):
123451
So I changed to:
I don't know if there is a cleanest way to do it
Looks good to me
Allan
Sorry, @carrarachristophe , yep, I said what to do, then promptly mistyped it, omitting the
val()
. Glad all sorted,Colin
No worries.
You pointed me to the right direction.
Take care.