# 追加画面・編集画面で入力に応じて赤文字にしたい

**URL:** <https://community.cybozu.dev/t/topic/3347>\
**Category:** kintone 開発相談\
**Created:** [September 6, 2018, 10:49am UTC](https://community.cybozu.dev/t/topic/3347 "2018-09-06T10:49:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account1944](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Legacy\_Account1944](https://community.cybozu.dev/u/Legacy_Account1944)\
**Post date:** [September 6, 2018, 10:49am UTC](https://community.cybozu.dev/t/topic/3347/1 "2018-09-06T10:49:04Z")

</div>

いつも大変お世話になっております。

追加画面・編集画面で  
入力した文字を赤くしたり、太文字にしたり、  
することは可能でしょうか？

以前に同じような質問をして解決しなかった（ここの箇所に対しての回答なし）ので、質問致しました。

わかる方・詳しい方、ご教授頂きたいです。  
よろしくお願いします。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1968](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Legacy\_Account1968](https://community.cybozu.dev/u/Legacy_Account1968)\
**Post date:** [September 10, 2018, 1:55am UTC](https://community.cybozu.dev/t/topic/3347/2 "2018-09-10T01:55:39Z")

</div>

お世話になります。

&nbsp;

Kintone標準の「 kintone.app.record.getFieldElement() 」

が追加編集画面でも使用できれば簡単に実現できますのに。。。

&nbsp;

少々無理やりですが上記内容を実現できましたのでご紹介します。

下記方法以外で簡単に実現できる方法がありましたら私も知りたいです。

&nbsp;

※こちらの方法はKintoneのバージョンアップで動作しなくなる可能性があります。

※Jqueryを使用しています。使用しない場合はJS標準のDOM操作に変更すれば動くはずです。

&nbsp;

kintone.events.on([“app.record.edit.show”,“app.record.create.show”], function(e) {

&nbsp; &nbsp;&nbsp;//フィールドのIDを取得  
&nbsp; &nbsp;&nbsp;var id\_field1 = fieldIDRtn(“field1”);  
&nbsp; &nbsp;&nbsp;var id\_field2 = fieldIDRtn(“field2”);

&nbsp; &nbsp;&nbsp;//フィールドのエレメントを取得(jQuery)  
&nbsp; &nbsp;&nbsp;var $element\_field1 = $(‘.field-’ + id\_field1 + ’ input’);  
&nbsp; &nbsp;&nbsp;var $element\_field2 = $(‘.field-’ + id\_field2 + ’ input’);

&nbsp; &nbsp;&nbsp;//フィールド１を太文字、赤文字にする  
&nbsp; &nbsp;&nbsp;$element\_field1.css({  
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;‘color’:‘red’,  
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;‘font-weight’:‘bold’  
&nbsp; &nbsp;&nbsp;});

&nbsp; &nbsp;&nbsp;//フィールド２を太文字にする  
&nbsp; &nbsp;&nbsp;$element\_field2.css({  
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; ‘font-weight’:‘bold’  
&nbsp; &nbsp;&nbsp;});

});

/\*\*  
\* fieldElementのクラス名IDを取得  
\*  
\* @param {String} fieldCode フィールドコード  
\* @return {}  
\*/  
function fieldIDRtn(fieldCode) {  
&nbsp; &nbsp;&nbsp;var fieldObj = {};  
&nbsp; &nbsp;&nbsp;var fieldList = cybozu.data.page.SCHEMA\_DATA.table.fieldList;  
&nbsp; &nbsp;&nbsp;for(var i in fieldList) {  
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;if(fieldList[i].var == fieldCode) {  
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var fieldObj = fieldList[i];  
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;break;  
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;}  
&nbsp; &nbsp;&nbsp;}  
&nbsp; &nbsp;&nbsp;return fieldObj ? fieldObj.id : undefined;  
}

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1944](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Legacy\_Account1944](https://community.cybozu.dev/u/Legacy_Account1944)\
**Post date:** [September 19, 2018, 9:31am UTC](https://community.cybozu.dev/t/topic/3347/3 "2018-09-19T09:31:21Z")

</div>

返答ありがとうございます！  
赤文字・太文字はできるようになりました。助かりました！

ここの質問の箇所は希望通りにできたのですが、  
最終の希望通りは できずにいます。

入力された数値テキストの合計がマイナスだった場合、  
「マイナスですよ！再確認してください！」  
と赤い太文字で表示したいのですが、

ワンテンポ遅れるというか、  
マイナスの数値テキストを入力して、次のテキストを入力してから、  
赤い文字になります。

すごく悩んでいるのですが、このズレはどうしようもないですかね。。。

前回の質問：  
[https://developer.cybozu.io/hc/ja/community/posts/360021222931-%E3%83%95%E3%82%A3%E3%83%BC%E3%83%AB%E3%83%89%E3%81%AE%E5%80%A4%E3%81%8C%E3%83%9E%E3%82%A4%E3%83%8A%E3%82%B9%E3%81%AE%E6%99%82%E3%81%A0%E3%81%91-%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E3%81%AE%E8%89%B2%E3%82%92%E8%B5%A4%E8%89%B2%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84%E3%81%A7%E3%81%99-](https://developer.cybozu.io/hc/ja/community/posts/360021222931-%E3%83%95%E3%82%A3%E3%83%BC%E3%83%AB%E3%83%89%E3%81%AE%E5%80%A4%E3%81%8C%E3%83%9E%E3%82%A4%E3%83%8A%E3%82%B9%E3%81%AE%E6%99%82%E3%81%A0%E3%81%91-%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E3%81%AE%E8%89%B2%E3%82%92%E8%B5%A4%E8%89%B2%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84%E3%81%A7%E3%81%99-)
