フィリピンの者です。
*.change.<フィールドコ> は field というオブジェクトがあると思いますが、
どうやって変更された要素のフィールドコードを取得出来ますか。
typeにはストリングを操作?して取得可能だと思いますが、よりスマートな方法はありますか。
Is there a smarter way to retrieve the field code from the element that triggered the change event?
どうぞよろしくお願いいたします。
初めまして、
イベントハンドラーを既に登録しているのであれば、
event.typeから発生したイベントの種類を取得できます。
そこから、文字列を編集して取得できるかと思います。
目的がわかりませんでしたが、私の解釈で回答しました。
if you set event handler already, you can retrieve field code from string of event type.
Then, you can split by string of “change.”, returns array that have 2 elements,[‘app.record.create.’,‘XXX’].
It useful for many field change event at the same time like below.
I could not to understand your purpose why you asked about this topic, I answered in my interpretation.
kintone.events.on(['app.record.create.change.test','app.record.create.test2'], function(event) {
console.log(event.type.split('change.')[1]);
});
岡崎 光輝 , Ryoji さま
ご回答ありがとうございます。
events.typeからのストリングで取得出来ますね。
event.changes.field.disabled というプロパティは設定出来るので、
event.changes.fieldというオブジェクト自体からフィールドコードが取得出来ないでしょうか。
以下は普通に作動します。
export const onFieldChangeHandler = (event) => {
const {changes: {field}} = event;
field.disabled = true;
// someFunctionThatNeedsFieldCode(field.code)
return event;
};
field.code のようなプロパティはないでしょうか。
Is there a way to get the field code from the events.change.field object itself?
なぜ必要なのか:
The company made a very large form, around 400 fields. Many of it appears conditionally based on selected value from radio or dropdown fields.
They also change these conditions often.
I want to streamline this by using a json file as a settings file where I can define the visibility based on the choice.
Here is my test app.:
Here is the JSON file.
例:Aラジオフィールに
-
"表示"を選択した場合、"show"というプロパティにあるフィールドの配列を全部表示に設定する。
-
"非表示"を選択された場合、設定のファイルにないので表示の逆の設定をする。
{
"A" : {
"表示" : {
"show" :
["A_F_1"]
}
},
"B" : {
"2" : {
"show" :
["B_F_1"],
"hide":
["B_F_2"]
}
}
}
もし、フォームに変化があった場合、表示・表示の仕組みはJSコードを弄らず、このファイルで設定出来ます。
この仕組みはもう出来ていますが、changes.field からフィールドコードが取得出来れば、event.typeのストリングから取得するより、cleanに見えるかなと思います。
Lorenz Rasさん、
event.changes.field.codeのようなプロパティは存在しませんが、
こちらで動作できませんか?
Could you check source below??
export const onFieldChangeHandler = (event) => {
const {changes: {field}} = event;
field.disabled = true;
someFunctionThatNeedsFieldCode(event.type.split('change.')[1]);
return event;
};
質問を読み違えていました。
fieldオブジェクトにはvalueとtypeしかないので、岡崎 光輝さま記載のとおりになります。
岡崎 光輝, Ryoji さま
disabledというプロパティも存在しませんが、普通に使えます。
同じくフィールドコードも取得出来ないかなと質問させていただきました。
オブジェクトから、使えるプロパティやメソッドが全部取得する方法はありますか。
disabledのように、ドキュメンテーションやconsole.log()にないのに、普通に使えますから、気になりました。