0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AgileWorks】数値フィールドでgetValue()を行うと未入力でも0が返される

Posted at

はじめに

以前、AgileWorks の入力チェックで
金額欄がブランクだったらエラーを出すように開発した時の話です。

問題

何も考えず以下のようにソースコードを書いてテストを行ったところ、
金額欄の項目には何も入力していない(ブランクの状態の)はずなのに
if文の中は通りませんでした。

var money = table.getField(row, "money").getValue();

if(money = "")
{
    // エラー処理
}

解決策

結論、金額欄の値を呼び出している箇所を
getValue()からgetTextValue()に変えれば
ブランクかどうかの判定ができるようになりました。

var money = table.getField(row, "money").getTextValue();

if(money = "")
{
    // エラー処理
}

さいごに

数値フィールド、整数フィールドの設定値を文字列のまま取得する場合は
getTextValue()を使う必要があるみたいです。

逆を言えば、
数値フィールド、整数フィールドは内部的に初期値0が格納されているようなので注意が必要です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?