Text Entry
Text entry form fields are designed for open-ended questions that demand short answers. You can also require that respondents enter specific values, such as an e-mail address or password. This example demonstrates different types of text box questions supported by SurveyJS Form Library. Switch between React, Vue, Vanilla JavaScript, jQuery, and Angular to view an example for your JavaScript framework.
Create a Text Entry Question
To create a text entry form field, define an object with the type property set to "text" and add it to the elements array. Within this object, specify the question's title and a unique name that identifies the text input question. Optionally, you can specify a description to place under the title and a placeholder to show within the text entry box.
Specify Input Type
If a question requires specific values, use the inputType property to specify the input type. An inputType value is passed on to the type attribute of the underlying <input> HTML element. This example demonstrates the "email", "password", "url", and the default "text" input types.
In addition, you can specify the autocomplete property to let the browser suggest autofill values. For example, the "E-mail address" and "Password" form fields in this demo can be populated automatically if your browser contains autofill e-mail and password values.
Validate Text Values
If you need to ensure that respondents fill out all required form fields and the format of values is correct, enable data validation. This example demonstrates the following validation types and describes how to configure them:
Required Validation
Enable theisRequiredproperty for the form fields that should not be empty.Text Length Validation
Define an object with thetypeproperty set to"text"and add it to thevalidatorsarray. Use theminLengthandmaxLengthproperties within this object to limit the text length (see the "Password" form field in this demo).RegEx Validation
Define an object with thetypeproperty set to"regex"and add it to thevalidatorsarray. Assign a regular expression to theregexproperty within this object (see the "URL" form field in this demo).
To learn more about data validation in SurveyJS Form Library, refer to the following help topic: Data Validation.