Getting Started

This section explains briefly about how to create a NumericTextBox control in your application with JavaScript. From the following steps you can learn how to create and use NumericTextBox  in your application. Here we have showcased the Textbox controls.

Create Textboxes Widgets

Essential JavaScript includes angular directives for all controls with the ej.widget.angular.min.js script file. All the Essential JS directives have been encapsulated into a single module called ejangular. To render our ej controls in angular, you need to refer the “angular.min.js” and “ej.widget.angular.min.js” in your application.

Create an HTML file and add the following template to the HTML file for Textbox widget creation.

  • html
  • <!doctype html>
    <html lang="en" ng-app="EditCtrl">
    <head>
        <title>Essential Studio for JavaScript : AngularJS Support for Numeric Textbox </title>
        <!-- Style sheet for default theme (flat azure) -->
        <link href="http://cdn.syncfusion.com/18.3.0.35/js/web/flat-azure/ej.web.all.min.css" rel="stylesheet" />
        <!--Scripts-->
        <script src="http://cdn.syncfusion.com/js/assets/external/jquery-1.11.3.min.js" type="text/javascript"> </script>
        <script src="http://cdn.syncfusion.com/js/assets/external/jquery.easing.1.3.min.js" type="text/javascript"></script>
        <script src="http://cdn.syncfusion.com/js/assets/external/angular.min.js"></script>
        <script type="text/javascript" src="http://cdn.syncfusion.com/18.3.0.35/js/web/ej.web.all.min.js "></script>
        <script src="http://cdn.syncfusion.com/18.3.0.35/js/common/ej.widget.angular.min.js"></script>
        <!--Add custom scripts here -->
    </head>
    <body>
        <!--Add the Textbox elements here-->
    </body>
    </html>

    The ng-app directive explains the root element (<html> or <body> tags) of the application. You will assign a name to the ng-app directive, then you must create a module with that name. In this module, you will have to define your directives, services, filters and configurations.

    Properties can be bind to ejNumericTextbox control using the prefix e- and particular property name as shown as below

    Add the input elements

  • html
  • <table  style="margin: auto">
    <tbody>
    <tr>
        <td>
            <span>Numeric Textbox</span>
        </td>
    </tr>
    <tr>
        <td>
            <input id="numeric" type="text" ej-numerictextbox e-value="numericValue" />
        </td>
    </tr>
    </tbody>
    </table>

    Set the value in the controller

  • html
  • angular.module('EditCtrl', ['ejangular'])
               .controller('EditorsCtrl', function ($scope) {
                   $scope.numericValue = 600;
               });

    Execute the above code to render the following output

    Set the MinValue, MaxValue and Value in Textboxes

    You can set the minValue”, maxValue and value in Numeric, Percentage and Currency text boxes for maintaining the range in Textboxes widgets. In this scenario, you have to enter the values between the given ranges. The following code example illustrates how to achieve this.

  • html
  • <table style="margin: auto">
    <tbody>
    <tr>
        <td>
            <span>Numeric Textbox</span>
        </td>
    </tr>
    <tr>
        <td>
            <input id="numeric" type="text" ej-numerictextbox e-value="100" e-maxvalue="1000" />
        </td>
    </tr>
    </tbody>
    </table>

    The following screenshot shows the output for the above code

    Set the Strict Mode option

    You can set the “StrictMode option to restrict entering values defined outside the range. The following code example illustrates how to set strict mode option.

  • html
  • <table style="margin: auto">
    <tbody>
    <tr>
        <td>
            <span>Numeric Textbox</span>
        </td>
    </tr>
    <tr>
        <td>
            <input id="numeric" type="text" ej-numerictextbox e-value="100" e-maxvalue="1000" e-enablestrictmode="true" />
        </td>
    </tr>
    </tbody>
    </table>

    The following screenshot show the output the for the above code

    Data Binding

    The EJ Textbox supports the data binding. When a widget’s model attribute is bound to a scope variable, it has been bound in one way.

    We have listed the properties of Textbox widget that supports two way binding:

    control

    Supported properties

    ejNumericTextbox



    Value



    Please use the below code to bind the Textbox in two-way support.

  • html
  • <table style="margin: auto">
    <tbody>
    <tr>
        <td>
            <span>Numeric Textbox</span>
        </td>
    </tr>
    <tr>
        <td>
            <input id="numeric" type="text" ej-numerictextbox e-value="numericValue" />
        </td>
    </tr>
    <tr> 
        <td>
            <input type="text" class="input ejinputtext" ng-model="numericValue" /><br />
        </td>
    									
    </tr>
    </tbody>
    </table>
  • html
  • angular.module('EditCtrl', ['ejangular'])
    .controller('EditorsCtrl', function ($scope) {
    $scope.numericValue = 600;
    });

    In the above sample, Textbox value was bind in two way method. Changes made in the textbox will reflect to another textbox.

    Run the above code to render the following output.