Question About setFieldShown

Dear Developers

It’s on Detail, after you click on a detail of record on index

I was able to hide a Field simply by typing

kintone.app.record.setFieldShown(“field_name”, false);

However, after I set two field into a table, I’m able to hide the table but can’t hide the field (row)

Let’s say: table=table_ab, field 1=A, field 2=B

I’m able to hide the table_ab, but cant hide A using kintone.app.record.setFieldShown(“A”, false);

Please help, any answer would be appreciated, thank you

Hello Afief,
This can be done by using the JS and the CSS. The scripts are something like the following:

Javascript

(function() {
"use strict";
kintone.events.on(["app.record.detail.show"], function(event) {
document.getElementById('record-gaia').classList.add('xxx-show');
return event;
});
})();

CSS:

.xxx-show .subtable-gaia th:nth-child(2),
.xxx-show .subtable-gaia td:nth-child(2) {
display: none;
}

The above sample scripts will hide the 2nd field in a table upon displaying the record detail.
If you want to hide the 3rd field in a table, change the “nth-child(2)” to “nth-child(3)” in the CSS script.
Also FYI, you need to create separate files for the Javascript and the CSS.

And lastly, these scripts are utilizing the DOM so it may not work one day after any kintone update when the DOM structure changes.

I hope this helps.

Just to note, kintone.app.record.setFieldShown() cannot be used against fields inside tables

Hello Yuzo and William

The problem has been fixed, I found the solution based on what you posted here, thank you very much, I appreciate it