directus-conditional-fields icon indicating copy to clipboard operation
directus-conditional-fields copied to clipboard

Trying to hide a filed of type slug fails

Open lahdekorpi opened this issue 4 years ago • 3 comments

image

lahdekorpi avatar Mar 10 '21 14:03 lahdekorpi

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?

flicksolutions avatar Apr 15 '21 15:04 flicksolutions

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...

flicksolutions avatar Apr 26 '21 12:04 flicksolutions

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.

goggi avatar May 24 '21 07:05 goggi

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?

SalahAdDin avatar Aug 20 '22 21:08 SalahAdDin