標準的な<input>を文字列型、数値型、boolean型から
選んだ型の値のフィールドに置換します。
型: String
この値が定義されている場合、
typeFieldが定義されていなければデフォルトのinputフィールドの型を設定します。
$(".input").typedInput({
default: "msg"
});
型: Array
この要素が提供する型の一覧を設定します。
このオプションの値は、 定義済みの型およびカスタムした型のTypeDefinitionオブジェクトの文字列識別子の配列です。
定義済みの型は以下のとおりです。:
| 識別子 | 説明 |
|---|---|
msg |
msg.プロパティ式 |
flow |
flow.プロパティ式 |
global |
global.プロパティ式 |
str |
文字列 |
num |
数値 |
bool |
Boolean |
json |
有効なJSON文字列 |
bin |
Node.js Buffer |
re |
正規表現 |
jsonata |
Jsonata式 |
date |
現在のタイムスタンプ |
env |
環境変数 |
node |
node.プロパティ式 |
cred |
セキュアクレデンシャル |
$(".input").typedInput({
types: ["msg","str"]
});
型: CSSセレクタ
特定の状況では、typedInputの型を保存するために<input>要素を既に持っていることが望ましいです。
このオプションでは存在している要素に型を設定しておくことができます。
typedInputの型が変更されたとき、
inputの型も変更されます。
$(".input").typedInput({
typeField: ".my-type-field"
});
When used in a Node-RED node, this value can be stored as a node property by adding
an entry for it in the node’s defaults object. This ensures the type is saved
along with the value in the node configuration.
<div class="form-row">
<label>Example:</label>
<input type="text" id="node-input-myField">
<input type="hidden" id="node-input-myFieldType">
</div>
RED.nodes.registerType('example', {
defaults: {
myField: { value: "" },
myFieldType: { value: "str" }
},
...
oneditprepare: function () {
$("#node-input-myField").typedInput({
typeField: "#node-input-myFieldType"
});
}
})
Since Node-RED 1.2.7
Disable the typedInput when it is currently enabled.
The optional state parameter can be used to toggle the disabled/enabled state of the typedInput. If state is true, the element will be disabled, otherwise it will be enabled.
$(".input").typedInput('disable');
Since Node-RED 1.2.7
Returns: Boolean
Gets whether the typedInput is currently disabled or not.
$(".input").typedInput('disabled');
Since Node-RED 1.3.3
Enable the typedInput when it is currently disabled.
$(".input").typedInput('enable');
Hide the typedInput when it is currently visible.
$(".input").typedInput('hide');
Show the typedInput when it is currently hidden.
$(".input").typedInput('show');
戻り値: String
選択しているtypedInputの型を取得します。
var type = $(".input").typedInput('type');
選択しているtypedInputの型を設定します。
$(".input").typedInput('type','msg');
typedInputが提供する型の一覧を設定します。詳細はtypes optionを参照してください。
$(".input").typedInput('types',['str','num']);
戻り値: Boolean
typedInputの型/値の再検証をおこなわせます。 再検証は型または値が変更されたときに自動的に実行されますが、このメソッドによって手動で実行することができます。
var isValid = $(".input").typedInput('validate');
戻り値: String
typedInputの値を取得します。
var value = $(".input").typedInput('value');
typedInputの値を設定します。
$(".input").typedInput('value','payload');
typedInputのwidthを設定します。
$(".input").typedInput('width', '200px');
inputの型または値が変更されたとき、トリガーされます。
$(".input").on('change', function(event, type, value) {} );
Note: valueプロパティはNode-RED 1.3で追加されました。
TypeDefinitionオブジェクトは、
typedInput要素で提供される型を記述します。
オブジェクトには以下のプロパティが設定できます。:
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
value |
string | yes | 型の識別子 |
label |
string | 型メニューで表示されるラベル | |
icon |
string | 型メニューで表示されるアイコン | |
options |
array | この型が固定値を持つ場合の値の文字列オプションの配列。例えば、boolean型の場合は["true","false"]となります。 |
|
multiple |
boolean | If options is set, this can enable multiple selection of them. |
|
hasValue |
boolean | この型に関連付けられた値がない場合、falseが設定されます。 |
|
validate |
function | 型の値を検証するfunction | |
valueLabel |
function | A function that generates the label for a given value. The function takes two arguments: container - the DOM element the label should be constructed in, and value. |
|
autoComplete |
function | Since 2.1.0. If set, enable autoComplete on the input, using this function to get completion suggestions. See autoComplete for details. This option cannot be used with options, hasValue=false or valueLabel |
<input type="text" id="node-input-example1">
$("#node-input-example1").typedInput({
type:'str',
types:['str','num','bool']
})
<input type="text" id="node-input-example2">
$("#node-input-example2").typedInput({
type:'msg',
types:['msg']
})
<input type="text" id="node-input-example3">
$("#node-input-example3").typedInput({
type:'flow',
types:['flow','global']
})
<input type="text" id="node-input-example4">
$("#node-input-example4").typedInput({type:"fruit", types:[{
value: "fruit",
options: [
{ value: "apple", label: "Apple"},
{ value: "banana", label: "Banana"},
{ value: "cherry", label: "Cherry"},
]
}]})
<input type="text" id="node-input-example5">
$("#node-input-example5").typedInput({type:"fruit", types:[{
value: "fruit",
multiple: true,
options: [
{ value: "apple", label: "Apple"},
{ value: "banana", label: "Banana"},
{ value: "cherry", label: "Cherry"},
]
}]})
Due to the way the typedInput enhances a regular HTML <input>, its value is
stored as a string. For example, booleans are stored as "true" and "false".
When stored as node properties, it is necessary for the runtime part of the node to parse the string to get the typed value.
A utility function is provided to handle the built-in types provided by the TypedInput.
RED.util.evaluateNodeProperty(value, type, node, msg, callback)
| Property | Type | Required | Description |
|---|---|---|---|
value |
string | yes | The property to evaluate |
type |
string | yes | The type of the property |
node |
Node | yes, for certain types | The node evaluating the property |
msg |
Message Object | yes, for certain types | A message object to evaluate against |
callback |
Callback | yes, for flow/global types |
A callback to receive the result |
For most types, the function can be used synchronously without providing a callback.
const result = RED.util.evaluateNodeProperty(value, type, node)
For msg type, the message object should also be provided:
const result = RED.util.evaluateNodeProperty(value, type, node, msg)
To handle flow and global context types, the node needs to be provided as well as
a callback function due to the asynchronous nature of context access:
RED.util.evaluateNodeProperty(value, type, node, msg, (err, result) => {
if (err) {
// Something went wrong accessing context
} else {
// Do something with 'result'
}
})
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy