User tests: Successful: Unsuccessful:
This PR adds the ability to use a multiple field dependencies in showon form field attribute.
showon="field1:value1[OPERATOR]field2:value1,value2"
This is needed, for instance, in #8442 , but could really be used in many cases.
Apply the patch and refresh javascript cache.
Test if all current showon fields (config, recaptcha plugin, tinymce, etc) are working properly
Hint: To check where showon is being used use (in Linux): egrep -R 'showon=' /path/to/joomla/
Change a field in /administrator/components/com_config/model/form/application.xml
to use multiple dependencies, for instance, replace:
showon="mailer:sendmail"
for
showon="mailonline:1[AND]mailer:sendmail"
or
showon="mailonline:1[OR]mailer:sendmail"
And test if jform[sendmail]
field (Sendmail Path) in global config only appears when jform[mailonline]
(Send Mail) is set to "Yes" and/or jform[mailer]
(Mailer) is set to "Sendmail".
Other field showon test examples:
<field name="field1" type="checkbox" label="field1" value="1" default="0" />
<field name="field2" type="radio" label="field2" default="0" class="btn-group btn-group-yesno"><option value="1">1</option><option value="0">0</option></field>
<field name="field3" type="list" label="field3" default="0"><option value="1">1</option><option value="0">0</option></field>
<field name="field4" type="text" label="field4" default="0" />
<field name="field5" type="checkboxes" label="field5" default="0"><option value="2">2</option><option value="1">1</option><option value="0">0</option></field>
<field name="field6" type="list" label="field6" default="0" multiple="true"><option value="0">0</option><option value="1">1</option></field>
<field name="check1" type="text" label="shows on field1=1" showon="field1:1" />
<field name="check2" type="text" label="shows on field1=1 AND field1=1" showon="field1:1[AND]field2:1" />
<field name="check3" type="text" label="shows on field1=1 OR field2=1" showon="field1:1[OR]field2:1" />
<field name="check4" type="text" label="shows on field1=1 OR field2=1 OR field3=1" showon="field1:1[OR]field2:1[OR]field3:1" />
<field name="check5" type="text" label="shows on field1=1 AND field2=1 AND field3=1" showon="field1:1[AND]field2:1[AND]field3:1" />
<field name="check6" type="text" label="shows on field1=1 AND field2=1 OR field3=1" showon="field1:1[AND]field2:1[OR]field3:1" />
<field name="check7" type="text" label="shows on field1=1 OR field2=1 AND field3=1" showon="field1:1[OR]field2:1[AND]field3:1" />
<field name="check8" type="text" label="shows on field1=1 AND field2=1 AND field3=1 AND field4=1" showon="field1:1[AND]field2:1[AND]field3:1[AND]field4:1" />
<field name="check9" type="text" label="shows on field5 as 0" showon="field5:0" />
<field name="check10" type="text" label="shows on field5 as 1" showon="field5:1" />
<field name="check11" type="text" label="shows on field5 as 2" showon="field5:2" />
<field name="check12" type="text" label="shows on field5 as 1 or 0" showon="field5:1,0" />
<field name="check13" type="text" label="shows on field5 as 2,1 or 0" showon="field5:2,1,0" />
<field name="check14" type="text" label="shows on field1=1 AND field5 as 2 or 1" showon="field1:1[AND]field5:2,1" />
<field name="check15" type="text" label="shows on field6 as 0" showon="field6:0" />
<field name="check16" type="text" label="shows on field6 as 1 or 0" showon="field6:1,0" />
After update, just refresh javascript cache to refresh cms.js file (Ctrl + F5).
I don't know if i used some form classes properly. Please check code.
Improvements are welcome.
@dgt41 @infograf768
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
Milestone |
Added: |
So this would make it that both requirements need to be valid for the field to appear?
yes
Personally I would had needed it the other way, that only one of the requirements need to be true (eg either parameter foo or paramater bar need to be enabled).
But I can the need for both ways. Just not sure if we can support both behaviours somehow
I think, with some extra work, we can. :)
We can, for instance, use "&&" for AND and "||" for OR, instead of ";".
I will check that.
My fear is that the code becomes to complex, but if it's possible without to much complexity then I think that would be great and even more intuitive to use.
Will test tomorrow.
Category | ⇒ | JavaScript Libraries |
Easy | No | ⇒ | Yes |
I have tested this item successfully on de9181c
I tried this code and it works perfectly.
It works well in all fields type="radio" and type="list" but does not work in type="checkboxes" or with multiple = "true"
One problem encountered is that checkboxes not function as such and it functions as radio.
<field
name="field1"
type="checkboxes"
default="0"
label="Field1">
<option value="0">JNO
<option value="1">JYES
</field><field
name="field2"
type="text"
label="Field2"
showon="field1:1" />
You can tell me anything about it? Thank you
Thanks for your quick response @andrepereiradasilva
Your examples seem to work but try several checkbox
<field name="field0" type="checkboxes" default="0" label="field0"><option value="0">JNO</option><option value="1">JYES</option></field>
<field name="check1" type="text" label="shows on field0=1" showon="field0:1" />
ok. I see type="checkboxes"
didn't test that field type, only type="checkbox"
.
Yes, current it doesn't work in that field type, will see what i can do.
I hope you can find a solution.
Thanks for your great work.
You are the best!!
They also run the multiselects
<field name="field6" type="list" multiple="true" label="field6" default="0"><option value="2">2</option><option value="1">1<option value="0">0</option></field>
<field name="check15" type="text" label="shows on field6 as 2,1 or 0" showon="field6:2,1,0" />
@joboca
Can you test and click in Test This (after login) in https://issues.joomla.org/tracker/joomla-cms/8524 ?
I have tested this item successfully on ce936c7
Very necessary for new versions of Joomla
I have tested this item successfully on ce936c7
Status | Pending | ⇒ | Ready to Commit |
RTC :) Thanks
Labels |
Added:
?
|
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-01-17 13:02:44 |
Closed_By | ⇒ | wilsonge |
Labels |
Removed:
?
|
@andrepereiradasilva I had to manually fix conflicts here when merging it - could you please just double check everything is ok in the commit merging it into the CMS (aff4150). Thanks!
Milestone |
Added: |
Milestone |
Removed: |
@andrepereiradasilva
Is this now included into 3.5.1?
@hennysmafter This PR got merged for 3.5.0. See the milestone.
@Bakual Thank you for informing me. I saw the milestone but did not understand it as there where so many references. But your answer removes all doubts. Really happy with it. Thanks everyone!
When are the docs going to be updated with this new information? Can I update it?
@hennysmafter Please update the docs. It's a wiki, so anyone can update the docs.
Hi @andrepereiradasilva ,
It's possible to select a value empty ""
example:
<field name="field1"
default="">
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="field2"
showon="field1:" />
Thanks
It's possible to select a value empty ""
Please use the Google Group for such requests: https://groups.google.com/forum/#!forum/joomla-dev-general
@roland-d I just spent about 30 minutes in making all the functions available in the docs I press save and I get a bullshit reply that I am link spanning or something. I did not even add 1 link to the entire post!!!
Now everything is gone. What is this getting punished for making a contribution? Ridiculous now I understand why those docs are so many times outdated because really I wanted to make a difference on those docs but now not so much it is easier to add it in our own knowledge base. At least when I press save it gets saved.
I am writing it once more. And I will dump the entire thing in here. So anyone who is willing to deal with the Joomla Doc system please try adding it.
I am going to try if they accept it otherwise here is everything I changed I kept numbering up those translate items so those links inside noinclude
are not mine but where already present.
<translate><!--T:19-->
To combine multiple fields you can use <code>[AND]</code>. Like <code>showon="foo:1[AND]bar:1"</code></translate>
<translate><!--T:20-->
Syntax to show the field "bar" only when "foo" is set to "1" and "baz" is set to "1":</translate>
<source lang="php"><field
name="foo"
type="list"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="baz"
type="list"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="bar"
type="text"
showon="foo:1[AND]baz:1"
/></source>
<translate><!--T:21-->
Syntax to show the field "bar" only when "foo" is set to "1" or "baz" is set to "1":</translate>
<source lang="php"><field
name="foo"
type="list"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="baz"
type="list"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="bar"
type="text"
showon="foo:1[OR]baz:1"
/></source>
<translate><!--T:22-->
To create a choice between multiple fields you can use <code>[OR]</code>. Like <code>showon="foo:1[OR]bar:1"</code></translate>
<translate><!--T:23-->
This was introduced with PullRequest: https://github.com/joomla/joomla-cms/pull/3379, available starting with Joomla 3.2.4.</translate>
<noinclude>
<translate>
<!--T:24-->
[[Category:Landing Pages]]
[[Category:Form fields]]
[[Category:Development]]
</translate>
</noinclude>
Now I am getting another message:
This action has been automatically identified as harmful, and it has been disallowed. In addition, as a security measure, some privileges routinely granted to established accounts have been temporarily revoked from your account. A brief description of the abuse rule which your action matched is: Rep Filter
So basically I am the biggest terrorist walking around as I wanted to make one update to the docs and immediately I am punished for what??? Seriously I do not understand this at all. I have been making contributions to docs for years now. But the first time I make a contribution to the Joomla docs this stuff happens why oh why would anybody want to go through this stuff.
If anyone has a explanation please tell me...
@MATsxm @Hutchy68 I have heard you guys are the ones to talk about the docs. I wanted to make contributions but now not so much anymore I don't have time to deal with this crap. So I will post it on my own site and as you can see above is the entire text for you guys to update it yourself. If I got other usefull stuff I will try to add it if the system is acting stupid I put on my own site.
I can understand spam and rules and everything but please understand we have more stuff to do then updating docs.
@hennysmafter thanks for your contribution in the JDoc.
Do I have to mention here that we are all volunteers with also many stuff to do?
Btw, did you read the user account policy?
https://docs.joomla.org/JDOC:Wiki_policy which also has a specific link to:
https://docs.joomla.org/User:Abuse_filter which gives specifics as to why and how to re-enable your account?
Anyway, I will work on your changes (thanks again) when I'd have finished my other "stuff"
I understand that it is all based upon volunteers. And I also understand the position of the security but I also feel being punished for doing nothing wrong. And if you edit a article with many links init and then resupply that article without changing any of the links it is ridiculous to punish that user for supplying spam links as he/she did not do that.
I might read them but it might also be interesting to check the system of Gantry and how they handle user submitted data. Never had any trouble over there.
Everyone thank you for volunteering and doing your part making Joomla better. For me I will keep helping people in the different chat rooms.
@MATsxm I see you have updated it thank you so much I am sure this is going to be useful for hundreds of developers. I know I am already been a pain in your a* but I see that you deleted the beginning of the showon function. So now the start is not explained? In case this cannot be reverted or adapted please take a look here to see the original full function including the adaptations I made.
@hennysmafter thanks for the ping, should be ok now
What's your JDocs username please?
@hennysmafter just a hint: you could also use strings, multiple values (seperate by ,
) and/or multiple conditions
Examples:
showon="field0:custom"
showon="field1:1,2,3"
showon="field1:1[AND]field2:1[AND]field3:1,2"
showon="field1:1[OR]field2:1[OR]field3:1,2"
I understand that it is all based upon volunteers.
Yes it is
And I also understand the position of the security but I also feel being punished for doing nothing wrong.
It's not personal, it's a bot. It isn't punishing you or saying "not you again" so I suggest you read the links @MATsxm supplied.
And if you edit a article with many links init and then resupply that article without changing any of the links it is ridiculous to punish that user for supplying spam links as he/she did not do that.
It doesn't, the bot is smart enough to know what is new and what is not by user.
I might read them but it might also be interesting to check the system of Gantry and how they handle user submitted data. Never had any trouble over there.
LOL, apples and oranges. Probably has a human interaction at some point, no abuse filter is perfect nor can it be 100% right all the time. Plus, they are a business with paid employees not volunteers.
I sent you an email less than an hour after your edit was denied. I apologized to you, made some tweaks to the filter and asked you to try again. Your account was brand new, you never contributed to docs before, and I explained the filter that caught you was looking at the repetition of the text you submitted. Unless you can supply an army of editors to watch JDOCs around the clock and they are willing to approve and read every contribution to stop spammers, I suggest you show a little understanding to why your edit was blocked.
@andrepereiradasilva Hey thank you for letting me know that is really useful!
@Hutchy68 Thank you for actively helping me and also thank to @MATsxm for going above and beyond. Especially thank you for volunteering and spending the amounts of times you guys are putting in.
The last thing I want to say is this: Yes indeed my account was brand new but that was a eyeopener for me as well. Because I have been registered at Joomla for years now never ever thought that I needed to register for separate parts of the Joomla project. The error I received basically left me guessing at what I did wrong. Giving clearer error messages might be a good idea but on the other end it might give bad
people suggestions on how to circumvent the rules. I might never have contributed to the docs before but I am every single day of the year helping people via chat, phone and live working with Joomla and that is not because I am paid to do it because most of the time I am not.
But let's stop bitching against each other I am really happy that everyone can now share the new functions as they are amazing. Next time when I want to make a contribution I will be making it in my spare time and not during the normal business day as it will give me a bit more time. Luckily when things go wrong I can always ask you two. Plus I will be more patient.
Is there a place which is best to contact when there are questions about editing the docs?
Once again thank you. Sorry for angering, upsetting or irritating anyone who is/has reading these posts.
Is there a possibility of a negative match? For example, a list item where the default is blank. Another field might have showon="listfield:!" where ! represents any non-empty value.
Is there a possibility of a negative match? For example, a list item where the default is blank. Another field might have showon="listfield:!" where ! represents any non-empty value.
I don't think so.
How hard would it be to add a [NOT] operator?
as in showon="foo:1[NOT]bar:1"
where it will show on if foo == 1 unless bar == 1?
So this would make it that both requirements need to be valid for the field to appear?
Personally I would had needed it the other way, that only one of the requirements need to be true (eg either parameter foo or paramater bar need to be enabled).
But I can the need for both ways. Just not sure if we can support both behaviours somehow