directus-conditional-fields
directus-conditional-fields copied to clipboard
Trying to hide a filed of type slug fails

The code looks for an element with an attribute field that has the value of the field you want to show/hide.
document.querySelector("[field=" + el + "]")
For several types of fields, there is nothing like that. With m2m fields it's the same. The field-name is nowhere to be found, therefore it's not possible to show/hide the field with the method.
It might be necessary to reach out to the directus-staff that some reference to the field-name is neccesary in the markup... Maybe @MiniDigger can reach ou to someone of the directus team?
in .rc60 this should be possible now! At least for m2m fields it is possible... Will try make a PR for this during this week...
Still doesn't work for m2o fields. It's the same issue as flicksolution mentioned. The field/fields property is not populated.
I solved it temporarily with this:
hide(el) {
this.log("hide " + el);
var headings = document.evaluate("(//div[contains(concat(' ',normalize-space(@class),' '),' type-label ')]/span[contains(text(), '"+el+"')])[last()]", document, null, XPathResult.ANY_TYPE, null );
var node = headings.iterateNext();
if(node){
node.parentElement.parentElement.parentElement.parentElement.style.display = "none"
}
},
show(el) {
this.log("show " + el);
var headings = document.evaluate("(//div[contains(concat(' ',normalize-space(@class),' '),' type-label ')]/span[contains(text(), '"+el+"')])[last()]", document, null, XPathResult.ANY_TYPE, null );
var node = headings.iterateNext();
if(node){
node.parentElement.parentElement.parentElement.parentElement.style.display = "block"
}
}
It's far from perfect, but gets the job done. Instead of property field, it looks for the SPAN that contains the field name instead.
Still doesn't work for m2o fields. It's the same issue as @flicksolutions mentioned. The field/fields property is not populated.
I solved it temporarily with this:
hide(el) { this.log("hide " + el); var headings = document.evaluate("(//div[contains(concat(' ',normalize-space(@class),' '),' type-label ')]/span[contains(text(), '"+el+"')])[last()]", document, null, XPathResult.ANY_TYPE, null ); var node = headings.iterateNext(); if(node){ node.parentElement.parentElement.parentElement.parentElement.style.display = "none" } }, show(el) { this.log("show " + el); var headings = document.evaluate("(//div[contains(concat(' ',normalize-space(@class),' '),' type-label ')]/span[contains(text(), '"+el+"')])[last()]", document, null, XPathResult.ANY_TYPE, null ); var node = headings.iterateNext(); if(node){ node.parentElement.parentElement.parentElement.parentElement.style.display = "block" } }It's far from perfect but gets the job done. Instead of the property field, it looks for the SPAN that contains the field name instead.
@goggi Did you make a pull request?
@MiniDigger did you see this issue?