Single line text - Text question



var json =  { questions: [
     {name:"name", type:"text", title: "Please enter your name:", placeHolder:"Jon Snow", isRequired: true},
     {name:"birthdate", type:"text", inputType:"date", title: "Your birthdate:", isRequired: true},
     {name:"color", type:"text", inputType:"color", title: "Your favorite color:"},
     {name:"email", type:"text", inputType:"email", title: "Your e-mail:", placeHolder:"jon.snow@nightwatch.org", isRequired: true, validators: [{type:"email"}]}

window.survey = new Survey.Model(json);

    survey.onComplete.add(function(result) {
        document.querySelector('#surveyResult').textContent =
            "Result JSON:\n" + JSON.stringify(result.data, null, 3);

ReactDOM.render(<Survey.Survey model={survey}  />, document.getElementById("surveyElement"));

<!DOCTYPE html>
    <title>Single line text - Text question, Reactjs Survey Library Example</title>

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.6.0/polyfill.js"></script>
    <script src="https://unpkg.com/react@15/dist/react.js"></script>
    <script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
    <script src="https://unpkg.com/@babel/standalone@7.2.5/babel.min.js"></script>
<script src="https://surveyjs.azureedge.net/1.1.16/survey.react.js"></script>
<link href="https://surveyjs.azureedge.net/1.1.16/survey.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

                <div id="surveyElement">
    <div id="surveyResult"></div>

<script type="text/babel" src="./index.js"></script>


We are using HTML5 input type for this functionality. Please note, that some browsers do not support it. Here is the matrix of how browsers support HTML5 input type.

Here you cand find solutions with using third-party sripts:

By default the input type is "text" (inputType="text"). The following additional input types are available:

  • color
  • date
  • datetime
  • datetime-local
  • email
  • month
  • number
  • password
  • range
  • tel
  • text
  • time
  • url
  • week