Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

AppTextInput

A single-line TextInput with a given placeholder text (deprecated). More...

Import Statement: import Felgo 4.0
Inherits:

TextInput

Properties

Detailed Description

Note: AppTextInput is deprecated, please use AppTextField instead.

AppTextInput is an extension of the basic QML TextInput for getting single-line text input from the user. For multi-line text input, use AppTextEdit.

It adds the ability to display a placeholder text, which is visible as long as the text field is empty. The placeholder text's color and text can be configured using placeholderText and placeholderColor properties.

How do I set a placeholder for the text field?

Input controls like AppTextInput or AppTextField own a placeHolderText property, which you can use for your placeholder text.

 import Felgo
 import QtQuick

 App {
   AppPage {

     // remove focus from textedit if background is clicked
     MouseArea {
       anchors.fill: parent
       onClicked: textEdit.focus = false
     }

     // background for input
     Rectangle {
       anchors.fill: textEdit
       anchors.margins: -dp(8)
       color: "lightgrey"
     }

     // input
     AppTextInput {
       id: textEdit
       width: dp(200)
       placeholderText: "What's your name?"
       anchors.centerIn: parent
     }
   }
 }

How do I show validation errors?

The text input components provide predefined validators that you can use, they are called inputMethodHints.

You can also add custom validators to restrict the accepted input to a certain input type or expression. Input that does not match the validator is not accepted. To do custom validations and show errors for accepted input, you can add simple checks and control the visibility of errors with property bindings:

 import Felgo
 import QtQuick

 App {
   // background for input
   Rectangle {
     anchors.fill: textInput
     anchors.margins: -dp(8)
     color: "lightgrey"
   }

   // input
   AppTextInput {
     id: textInput
     width: dp(200)
     placeholderText: "What's your name?"
     anchors.centerIn: parent

     // only allow letters and check length
     validator: RegularExpressionValidator {
       regularExpression: /[A-Za-z]+/
     }
     property bool isTooLong: textInput.text.length >= 6
   }

   // show error if too long
   AppText {
     text: "Error: Use less than 6 letters."
     color: "red"
     anchors.top: textInput.bottom
     anchors.topMargin: dp(16)
     anchors.left: textInput.left
     visible: textInput.isTooLong
   }
 }

More Frequently Asked Development Questions

Find more examples for frequently asked development questions and important concepts in the following guides:

Property Documentation

[since Felgo 2.7.0] cursorColor : color

The color of the cursor that marks the current position in the text input. Matches Theme::inputCursorColor by default.

This property was introduced in Felgo 2.7.0.


[since Felgo 2.17.0] fontSize : int

Set a device-independent font size. It uses the App::sp() function internally. If you set font.pixelSize directly, this property will have no effect.

By default, the fontSize is 18 on Android and 17 on all other platforms.

This property was introduced in Felgo 2.17.0.


[since Felgo 2.7.0] placeHolderText : string

The text to display as placeholder, when the text field is empty.

This property was introduced in Felgo 2.7.0.


[since Felgo 2.7.0] placeholderColor : color

The color for the placeholder text.

The default value is Theme::placeholderTextColor.

This property was introduced in Felgo 2.7.0.


[since Felgo 2.7.0] placeholderText : alias

The text to display as placeholder, when the text field is empty.

This property was introduced in Felgo 2.7.0.


Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded