# VGSEditText

Provides a user interface element that displays text.

### Validation <a href="#validation" id="validation"></a>

Default behavior validates any user content. There are several ways to customize basic validation flow:

* **XML attributes**: `app:enableValidation`;
* **Validation builder**.

#### Determining validation rules <a href="#determining-validation-rules" id="determining-validation-rules"></a>

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val postalCode = findViewById(R.id.postalCode)

val rule : VGSInfoRule = VGSInfoRule.ValidationBuilder()
    .setRegex("<VALIDATION_REGEX>")
    .setAllowableMinLength(1)
    .setAllowableMaxLength(8)
    .build()

postalCode.setRule(rule)
```

{% endtab %}

{% tab title="Java" %}

```java
VGSEditText postalCode = findViewById(R.id.postalCode);

VGSInfoRule rule = new VGSInfoRule.ValidationBuilder()
    .setRegex("<VALIDATION_REGEX>")
    .setAllowableMinLength(1)
    .setAllowableMaxLength(8)
    .build();

postalCode.setRule(rule);
```

{% endtab %}
{% endtabs %}

### Set field name <a href="#set-field-name" id="set-field-name"></a>

Sets the text to be used for data transfer to VGS proxy. Usually, it is similar to field-name in JSON path in your inbound route filters. It is highly important to specify this parameter because the VGSCollect module relies on it too.

Warning: You must set up `fieldName` in other way input field will be ignored by VGSCollect.

{% tabs %}
{% tab title="XML" %}

```xml
<com.verygoodsecurity.vgscollect.widget.VGSEditText
    android:id="@+id/infoField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:fieldName="info_field_name>"/>
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val infoField = findViewById<VGSEditText>(R.id.infoField)
infoField.setFieldName("info_field_name")
```

{% endtab %}

{% tab title="Java" %}

```java
VGSEditText infoField = findViewById(R.id.infoField);
infoField.setFieldName("info_field_name");
```

{% endtab %}
{% endtabs %}

### Define the required state <a href="#define-the-required-state" id="define-the-required-state"></a>

Specifies whether the text inside input field is required to be filled.

When `app:isRequired` set as `true`, then input data should be valid only. If `app:isRequired` set as `false`, then input data will be valid in case the field is empty. Otherwise input data should be valid.

By default, widget is required.

{% tabs %}
{% tab title="XML" %}

```xml
<com.verygoodsecurity.vgscollect.widget.VGSEditText
    android:id="@+id/infoField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:isRequired="false"/>
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val infoField = findViewById<VGSEditText>(R.id.infoField)
infoField.isRequired(false)
```

{% endtab %}

{% tab title="Java" %}

```java
VGSEditText infoField = findViewById(R.id.infoField);
infoField.isRequired(false);
```

{% endtab %}
{% endtabs %}

### Specify the keyboard type <a href="#specify-the-keyboard-type" id="specify-the-keyboard-type"></a>

You should always declare the input method for this input fields by adding the `app:inputType` to tell the system displays the appropriate soft input method (such as an on-screen keyboard).

For example, if you'd like an input method for entering a phone number specify `app:inputType` as `number` or `numberPassword`&#x20;

{% tabs %}
{% tab title="XML" %}

```xml
<com.verygoodsecurity.vgscollect.widget.VGSEditText
    android:id="@+id/infoField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:inputType="number"/>
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val infoField = findViewById<VGSEditText>(R.id.infoField)
infoField.setInputType(InputType.TYPE_CLASS_NUMBER)
```

{% endtab %}

{% tab title="Java" %}

```java
VGSEditText infoField = findViewById(R.id.infoField);
infoField.setInputType(InputType.TYPE_CLASS_NUMBER);
```

{% endtab %}
{% endtabs %}

Supported input types:

* **none** - there is no content type.
* **text** - for normal text.
* **textPassword** - for text that is a password.
* **number** - for numeric only text.
* **numberPassword** - for numeric password text.
* **date** - for entering a date.
* **textCapCharacters** - capitalize all characters.
* **textCapWords** - capitalize the first character of every word.

### Additional XML attributes <a href="#additional-xml-attributes" id="additional-xml-attributes"></a>

<table data-header-hidden><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>Attribute</strong></td><td><strong>Description</strong></td></tr><tr><td><pre><code>app:inputType
</code></pre></td><td>Set the type of the content with a constant as defined for input field.</td></tr><tr><td><pre><code>app:imeOptions
</code></pre></td><td><p>Specify soft input method for the input method action. By default, the system uses a</p><pre><code>actionNext
</code></pre><p>Plain textor</p><pre><code>actionDone
</code></pre><p>Plain textaction.</p></td></tr><tr><td><pre><code>app:fontFamily
</code></pre></td><td>Default font family (named by string or as a font resource reference) for the text.</td></tr><tr><td><pre><code>app:fieldName
</code></pre></td><td>Sets the text to be used for data transfer to VGS proxy. Usually, it is similar to field-name in JSON path in your inbound route filters.</td></tr><tr><td><pre><code>app:isRequired
</code></pre></td><td>Specifies whether the text inside input field is required to be filled.</td></tr><tr><td><pre><code>app:textSize
</code></pre></td><td>Size of the text.</td></tr><tr><td><pre><code>app:ellipsize
</code></pre></td><td>If set, causes words that are longer than the view is wide to be ellipsized instead of broken in the middle.</td></tr><tr><td><pre><code>app:ellipsize
</code></pre></td><td>If set, causes words that are longer than the view is wide to be ellipsized instead of broken in the middle.</td></tr><tr><td><pre><code>app:text
</code></pre></td><td>Text to display.</td></tr><tr><td><pre><code>app:textColor
</code></pre></td><td>Text color.</td></tr><tr><td><pre><code>app:maxLines
</code></pre></td><td>Makes the View be at most this many lines tall.</td></tr><tr><td><pre><code>app:minLines
</code></pre></td><td>Makes the View be at least this many lines tall.</td></tr><tr><td><pre><code>app:textStyle
</code></pre></td><td>Style (normal, bold, italic) for text.</td></tr><tr><td><pre><code>app:cursorVisible
</code></pre></td><td>Makes the cursor visible (the default) or invisible.</td></tr><tr><td><pre><code>app:gravity
</code></pre></td><td>Specifies how to align the text by the view’s x- or y-axis when the text is smaller than the view.</td></tr><tr><td><pre><code>app:scrollHorizontally
</code></pre></td><td>When the text is allowed to be wider than the view (and therefore can be scrolled horizontally).</td></tr><tr><td><pre><code>app:hint
</code></pre></td><td>Hint text to display when the text is empty.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/android-sdk/vgsedittext.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
