แบบสำรวจการวิจัย: บอกให้เราทราบเกี่ยวกับประสบการณ์การใช้งาน Blockly
เริ่มแบบสำรวจ
ช่องป้อนข้อความ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ช่องป้อนข้อความจะจัดเก็บสตริงเป็นค่าและสตริงเป็นข้อความ ค่าของฟิลด์จะเป็นสตริงที่ถูกต้องเสมอ ส่วนข้อความอาจเป็นสตริงใดก็ได้ที่ป้อนลงในเครื่องมือแก้ไข
ช่องป้อนข้อความ

ช่องป้อนข้อความที่เปิดเครื่องมือแก้ไข

ช่องป้อนข้อความในบล็อกที่ยุบ

การสร้างวิดีโอ
JSON
{
"type": "example_textinput",
"message0": "text input: %1",
"args0": [
{
"type": "field_input",
"name": "FIELDNAME",
"text": "default text",
"spellcheck": false
}
]
}
JavaScript
Blockly.Blocks['example_textinput'] = {
init: function() {
this.appendDummyInput()
.appendField("text input:")
.appendField(new Blockly.FieldTextInput('default text'),
'FIELDNAME');
}
};
ตัวสร้างอินพุตข้อความจะรับค่าที่ไม่บังคับและโปรแกรมตรวจสอบที่ไม่บังคับ ค่าควรแคสต์เป็นสตริง หากเป็น null
หรือ undefined
ระบบจะใช้สตริงว่าง
นอกจากนี้ คําจํากัดความ JSON ยังให้คุณตั้งค่าตัวเลือกตรวจตัวสะกดได้ด้วย
การจัดรูปแบบและ XML
JSON
JSON สำหรับช่องป้อนข้อความมีลักษณะดังนี้
{
"fields": {
"FIELDNAME": "text"
}
}
โดยที่ FIELDNAME
คือสตริงที่อ้างอิงช่องป้อนข้อความ และค่าคือค่าที่จะใช้กับช่อง ค่าจะเป็นไปตามกฎเดียวกับค่าคอนสตรคเตอร์
XML
XML สำหรับช่องป้อนข้อความมีลักษณะดังนี้
<field name="FIELDNAME">text</field>
โดยที่แอตทริบิวต์ name
ของช่องมีสตริงที่อ้างอิงช่องอินพุตข้อความ และข้อความภายในคือค่าที่จะใช้กับช่อง ค่าข้อความภายในจะเป็นไปตามกฎเดียวกับค่าคอนสตรคเตอร์
การปรับแต่ง
ตรวจตัวสะกด
คุณสามารถใช้ฟังก์ชัน setSpellcheck เพื่อตั้งค่าว่าต้องการให้ช่องตรวจตัวสะกดข้อความอินพุตหรือไม่
ช่องป้อนข้อความที่มีและไม่มีการตรวจตัวสะกด

การตรวจตัวสะกดจะเปิดอยู่โดยค่าเริ่มต้น
ซึ่งมีผลกับแต่ละช่อง หากต้องการแก้ไขทุกช่อง ให้เปลี่ยนพร็อพเพอร์ตี้ Blockly.FieldTextInput.prototype.spellcheck_
การสร้างโปรแกรมตรวจสอบการป้อนข้อความ
ค่าของช่องป้อนข้อความคือสตริง ดังนั้นโปรแกรมตรวจสอบต้องยอมรับสตริงและแสดงผลสตริง null
หรือ undefined
ต่อไปนี้คือตัวอย่างโปรแกรมตรวจสอบที่นําอักขระ "a" ทั้งหมดออกจากสตริง
function(newValue) {
return newValue.replace(/a/g, '');
}

เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[[["\u003cp\u003eA text input field stores a string value and allows user text input, with the value always being a valid string.\u003c/p\u003e\n"],["\u003cp\u003eYou can create text input fields using JSON or JavaScript, customizing them with options like spellcheck and validators.\u003c/p\u003e\n"],["\u003cp\u003eText input fields can be serialized and deserialized using JSON or XML, representing the field name and value.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esetSpellcheck\u003c/code\u003e function allows control over individual field spellchecking, while \u003ccode\u003eBlockly.FieldTextInput.prototype.spellcheck_\u003c/code\u003e affects all fields.\u003c/p\u003e\n"],["\u003cp\u003eValidators for text input fields accept a string and return a modified string, null, or undefined to enforce specific input rules.\u003c/p\u003e\n"]]],["Text input fields store a string as both their value and text, with the value always being a valid string. Creation involves defining the field in JSON or JavaScript, specifying a default text and optional spellcheck. The constructor and JSON allow setting a value, defaulting to an empty string if `null` or `undefined`. Serialization uses JSON and XML, where field names and values are stored. Spellcheck can be toggled, and validators are functions that accept and return strings, `null`, or `undefined`.\n"],null,["# Text input fields\n\nA text input field stores a string as its value and a string as its text. Its\nvalue is always a valid string, while its text could be any string entered into\nits editor.\n\n#### Text input field\n\n#### Text input field with editor open\n\n#### Text input field on collapsed block\n\nCreation\n--------\n\n### JSON\n\n {\n \"type\": \"example_textinput\",\n \"message0\": \"text input: %1\",\n \"args0\": [\n {\n \"type\": \"field_input\",\n \"name\": \"FIELDNAME\",\n \"text\": \"default text\",\n \"spellcheck\": false\n }\n ]\n }\n\n### JavaScript\n\n Blockly.Blocks['example_textinput'] = {\n init: function() {\n this.appendDummyInput()\n .appendField(\"text input:\")\n .appendField(new Blockly.FieldTextInput('default text'),\n 'FIELDNAME');\n }\n };\n\nThe text input constructor takes in an optional value and an optional\n[validator](#creating_a_text_input_validator). The value should cast to a\nstring. If it is `null` or `undefined`, an empty string will be used.\n\nThe JSON definition also allows you to set the [spellcheck](#spellcheck) option.\n\nSerialization and XML\n---------------------\n\n### JSON\n\nThe JSON for a text input field looks like so: \n\n {\n \"fields\": {\n \"FIELDNAME\": \"text\"\n }\n }\n\nWhere `FIELDNAME` is a string referencing a text input field, and\nthe value is the value to apply to the field. The value\nfollows the same rules as the constructor value.\n\n### XML\n\nThe XML for a text input field looks like so: \n\n \u003cfield name=\"FIELDNAME\"\u003etext\u003c/field\u003e\n\nWhere the field's `name` attribute contains a string referencing a text input\nfield, and the inner text is the value to apply to the field. The inner\ntext value follows the same rules as the constructor value.\n\nCustomization\n-------------\n\n### Spellcheck\n\nThe\n[setSpellcheck](/blockly/reference/js/Blockly.FieldTextInput#setSpellcheck)\nfunction can be used to set whether the field spellchecks its input text or not.\n\n### Text input fields with and without spellcheck\n\nSpellchecking is on by default.\n\nThis applies to individual fields. If you want to modify all fields change the\n`Blockly.FieldTextInput.prototype.spellcheck_` property.\n\nCreating a text input validator\n-------------------------------\n\n| **Note:** For information on validators in general see [Validators](/blockly/guides/create-custom-blocks/fields/validators).\n\nA text input field's value is a string, so any validators must accept a string\nand return a string, `null`, or `undefined`.\n\nHere is an example of a validator that removes all 'a' characters from the\nstring: \n\n function(newValue) {\n return newValue.replace(/a/g, '');\n }"]]