# 空白以外 何か文言を入れたら文字色を変えたい

**URL:** <https://community.cybozu.dev/t/topic/1638>\
**Category:** kintone 開発相談\
**Created:** [2023 年 6 月 5 日午前 2:45 UTC](https://community.cybozu.dev/t/topic/1638 "2023-06-05T02:45:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account272](https://avatars.discourse-cdn.com/v4/letter/l/57b2e6/32.png) [@Legacy\_Account272](https://community.cybozu.dev/u/Legacy_Account272)\
**Post date:** [2023 年 6 月 5 日午前 2:45 UTC](https://community.cybozu.dev/t/topic/1638/1 "2023-06-05T02:45:44Z")

</div>

お世話になります。

タイトルの件ですが、レコード追加画面や詳細画面からの編集でフィールドa（文字列1行）に何か文言を入力した場合、一覧画面でフィールドaに入力した文言の文字色が赤色太字になるようにしたいです。

過去に別の条件で赤色太字にしたことがあり構文を参考に修正してみましたがどうしても上手くいきません。

ご教授いただけませんでしょうか。

よろしくお願いします。

&nbsp;

// このコードは、kintoneアプリケーションのレコード一覧画面において、  
// フィールドの表示をカスタマイズするためのイベントハンドラです。

// kintoneのイベントを監視するために、kintone.events.onメソッドを使用します。  
kintone.events.on(‘app.record.index.show’, (event) =\> {  
&nbsp; &nbsp; // フィールドのDOM要素を取得します。  
&nbsp; &nbsp; const elStatus = kintone.app.getFieldElements(‘a’);

&nbsp; &nbsp; // フィールドのDOM要素の数だけループ処理を行います。  
&nbsp; &nbsp; for (let i = 0; i \< elStatus.length; i++) {  
&nbsp; &nbsp; &nbsp; &nbsp; // イベントデータの中から、i番目のレコードを取得します。  
&nbsp; &nbsp; &nbsp; &nbsp; const record = event.records[i];

&nbsp; &nbsp; &nbsp; &nbsp;// レコードの値に応じて、スタイルを変更します。  
&nbsp; &nbsp; &nbsp; &nbsp; if (record[‘a’][‘value’].length === 0) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // aが空白以外の場合、文字色を赤に設定します。  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else’':  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elStatus[i].style.color = ‘#ff0000’; // 文字色を赤にする  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elStatus[i].style.fontWeight = ‘bold’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;  
&nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; }

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1177](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@Legacy\_Account1177](https://community.cybozu.dev/u/Legacy_Account1177)\
**Post date:** [2023 年 6 月 5 日午前 3:28 UTC](https://community.cybozu.dev/t/topic/1638/2 "2023-06-05T03:28:59Z")

</div>

```
        if (record['a']['value'].length === 0) {

            else'':

```

多分switch文と混同されているのではないかと思いますが、if文について[こちらのページ](https://techplay.jp/column/469)を参考にされると良いでしょう。

構文エラーが出ているはずなので、[動かない？そんな時はデバッグをしてみよう！](https://community.cybozu.dev/hc/ja/articles/207613916-%E5%8B%95%E3%81%8B%E3%81%AA%E3%81%84-%E3%81%9D%E3%82%93%E3%81%AA%E6%99%82%E3%81%AF%E3%83%87%E3%83%90%E3%83%83%E3%82%B0%E3%82%92%E3%81%97%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86-%E5%85%A5%E9%96%80%E7%B7%A8?_ga=2.179064487.288356139.1685923131-678176966.1685923131)を参考にデベロッパーツールの使い方を覚えるのをおすすめします。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account272](https://avatars.discourse-cdn.com/v4/letter/l/57b2e6/32.png) [@Legacy\_Account272](https://community.cybozu.dev/u/Legacy_Account272)\
**Post date:** [2023 年 6 月 5 日午前 4:45 UTC](https://community.cybozu.dev/t/topic/1638/3 "2023-06-05T04:45:29Z")

</div>

[mls-hashimoto](https://community.cybozu.dev/hc/ja/profiles/385013133091-mls-hashimoto) 様

お世話になります。

教えていただいたページを参考に修正してみたところ、正常に文字色を変更することができました。

ありがとうございました。

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/cybozu/original/1X/d5c841c3c5a6cb66eed514001c1b45147c9e1f4f.png) [@system](https://community.cybozu.dev/u/system)\
**Post date:** [2023 年 9 月 27 日午前 6:32 UTC](https://community.cybozu.dev/t/topic/1638/4 "2023-09-27T06:32:18Z")

</div>

このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。
