Skip to content

Code Reference

Moritz Tim W. edited this page Nov 7, 2023 · 34 revisions

Nodes

FormContainer: Container

Manages form submission and is intended to contain the form elements.

Properties

submit_button: [Submit]

Calls the submit() function when pressed.

protocol: Protocol

Handles the submission of the form.

Methods

_ready

Connects the submit_button's pressed signal to the submit method if submit_button is not null.

submit

Submits the form data to the protocol.

generate_fields_dict

-> Dictionary Generates a dictionary of the form data.

Parameters:

subject: Node = self The node to generate the dictionary from. This is mainly used for recursion.

is_input

-> bool Returns whether the given node is an input. Inputs are:

  • buttons except MenuButton
  • LineEdit
  • TextEdit
  • ItemList
  • Slider
  • SpinBox
  • GraphEdit

Parameters:

  • subject: Node

ValidatableLineEdit: LineEdit

LineEdit with a [validator].

Properties

validator: [Validator]

Methods

_init

Assigns the style from the [validator] if it exists.

ValidatableTextEdit: TextEdit

TextEdit with a [validator].

Properties

validator: [Validator]

Methods

_init

Assigns the style from the [validator] if it exists.

Resources

Protocol: Resource

Handles form submission and response.

Properties

Methods

submit

-> int Submits form data and returns HTTP status code of the response.

Parameters:

get_value

-> Variant Finds the value of the given Node based on its type.
Throws an error if the type is unknown.

BaseButton -> button_pressed: bool
LineEdit | TextEdit -> text: String
Slider | SpinBox -> value: float
GraphEdit -> get_connection_list(): Array[Dictionary]
ItemList -> items:

Array[{
	selected = is_selected(): bool,
	text = get_item_text(): String,
	icon = get_item_icon(): Texture,
	metadata = get_item_metadata(): Variant
}]

Validator: Resource

Validates Text Input according to rules about length and content.

Properties

REGEX_LIB: Array[String]

A collection of predefined regular expression patterns. Items correspond to the PredefinedRegex

required:= false

Input must have a value. [min_length] will be adjusted if needed.

_prev_min_length:= 0

temporary storage of min_length used by the setter of required

min_length:= 0

Minimum length of the input.

word_range: [Boundaries]

Minimum and Maximum number of matches for \w+ allowed

whitelist: [ListFilter]

List of allowed strings.

blacklist: [ListFilter]

List of prohibited strings.

PredefinedRegex: enum

  1. NONE
  2. ALPHABETICAL
  3. NUMERICAL
  4. ALPHANUMERICAL
  5. EMAIL_ADDRESS
  6. PHONE_NUMBER

predefined := PredefinedRegex.NONE

Predefined pattern to match against.

Behavior: enum

  1. MUST_MATCH_BOTH
    Input must match both the predefined and the custom regex (if both are set)
  2. CAN_MATCH_EITHER
    Input can match either the predefined or the custom regex (if at least one is set)

behavior := Behavior.ALLOW

How predefined and custom regexes are checked against in relation to each other.

custom := ".*"

Custom Pattern to match against.

normalise := false

Normalise the case before matching.

require_single_match := false

Don't allow any more than one match.

Methods

_init

-> void Compiles the custom regex

_on_text_changed

-> void Validates given text and updates valid property.

Parameters:
  • new_text: String New content of the input

validate

-> bool Validates given text against all rules and returns validity

Parameters:
  • subject: String Text to validate

Boundaries: Resource

An upper and lower bound of an integer value.

Properties

min: int

Lower bound

max: int

Upper bound

Methods

has

-> bool Determines if the subject is within the boundaries.

Parameters:
  • subject: int

ListFilter: Resource

A filter with a blacklist or whitelist of strings

Properties

Match: enum

  1. ALL
    All elements must be present
  2. AT_LEAST_ONE
    At least one element must be present

match : Match

Match requirement

elements: Array[String]

The blacklist or whitelist

Methods

is_represented_in

-> bool Returns wether the subject is represented in the list

Parameters:
  • subject: String

size

-> int Returns the output of elements.size()

Protocols

NetworkProtocol: Protocol

Handles form submission and response over the network.

Properties

host := localhost

Target hostname

port := -1

Target port -1 means "use default port"

use_host_authentication := false

Use authentication for target

host_username := ""

Username at target

host_password := ""

Password at target

host_keyfile := ""

Path to private key file

Methods

_init

-> void Tries to set host_username based on environment var, if not already seties to set host_username based on environment var, if not already set

HttpProtocol: NetworkProtocol

Handles form submission and response over the network using HyperText Transfer Protocol
Web export is not supported.
Based on tutorial Godot Docs > Tutorials > Networking > HTTP Client Class

Properties

encrypt := true

Use HTTPS

path := "/"

Target path

Method: enum

  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • OPTIONS
  • TRACE
  • CONNECT
  • PATCH

method := Method.POST

HTTP Method

headers := {}

HTTP Headers

http := HTTPClient.new()

HTTP Client

base_url: String

{protocol}://{host}

Signals

response_received

Parameters:
  • code : int HTTP Status Code
  • headers : Dictionary
  • body : PackedByteArray

Methods

_init

-> void Sets the port to 443 if encrypt is true, otherwise 80, if it is set to -1.

submit

Submits form data and returns HTTP status code of the response.
Web export is not supported.

Parameters:
  • fields: Dictionary

http_client_status_to_string

-> String Returns a string representation of the HTTPClient.STATUS_. or "Status: {status}" if the status is not one of the following: 2. Error resolving host {host} 4. Error connecting to host {host}:{port} 8. Error in HTTP connection 9. Error in TLS handshake

Parameters:
  • status: int Status returned by HTTPClient.get_status()

MailProtocol: NetworkProtocol

Handles form submission and response over the network using E-Mail.

Properties

BodyFormat: enum

  • HTML
    Stylable HyperText Markup Language Form with disabled inputs
  • PLAIN_TEXT
    {key}: {value}
  • JSON
    JavaScript Object Notation

body_format := BodyFormat.HTML

css := "{addon_path}/styles/default.css"

Path to CSS file to use for styling regardless of body_format

from_name: String

Sender name

from_address: String

Sender address

to_address: String

Recipient address

subject: String

Subject line

Methods

submit

-> int Submits form data in an E-Mail to the recipient and returns HTTP status code of the response.

Parameters:
  • fields: Dictionary

generate_body

-> String Generates the body for the E-Mail

Parameters:
  • fields: Dictionary Output of FormContainer.generate_fields_dict() to populate body

type_to_string

-> String Converts a type to a string for use in HTML form.
TYPE_STRING -> "text"
TYPE_BOOL -> "checkbox"
TYPE_INT -> "number"
TYPE_FLOAT -> "number"
TYPE_ARRAY -> "select"
TYPE_NIL -> "text"

Parameters:
  • type: int Output of typeof()

get_value

-> String Returns the value of a node as a string for use in the E-Mail body.

Clone this wiki locally