Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Hi,
the paragraph showing the error message wouldn't display, I use ng-if,
I would like the paragraph to appear bellow my input textbox when textbox is empty or too short.


HTML
<form class="form-horizontal" role="form" name="editForm" novalidate>
    <div>
        <table>
            <tbody>
                <tr ng-repeat="testing in $data">
                    <td data-title="'Name'">
                        <div>
                            <input type="text" class="f-control" name="name" ng-model="testing.name" placeholder="Name" required ng-minlength="2" ng-maxlength="10">
                            <p class="help" ng-if="editForm.name.$error.required">Name is required</p>
                            <p class="help" ng-if="editForm.name.$error.minlength">Too Short</p>
                            <p class="help" ng-if="editForm.name.$error.maxlength">Too Long</p>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</form>


What I have tried:

I'm stuck here, is it I lack something?
Posted
Updated 29-Oct-16 6:31am
v4
Comments
Karthik_Mahalingam 3-Jun-16 6:43am    
angular.io ?

try this, little tricky :)

HTML
<!DOCTYPE html>
<html lang="en-US">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

    
    <script>
        var app = angular.module('myapp', []);
        app.controller('myctrl', myfun);
     

        function myfun($scope) {
            $scope.$data = [{ name: 'helicopter' }, { name: 'Aeroplane' }, { name: 'professional Team' }];
            $scope.isMax = function (index) {
                return $scope.editForm['name' + index].$error.maxlength;
            }
        }

    </script>


</head>
<body ng-controller="myctrl" ng-app="myapp">

    <form ng-controller="myctrl" ng-app="myapp"   class="form-horizontal" role="form" name="editForm" novalidate>
        <div>
            <table>
                <tbody>
                    <tr ng-repeat="testing in $data">
                        <td data-title="'Name'">
                            <div>
                                <input type="text" class="f-control" name="{{'name' + $index }}" ng-model="testing.name" placeholder="Name" required ng-minlength="2" ng-maxlength="10">
                                <b ng-show="isMax($index)"> Too Long</b>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </form>
</body>
</html>
 
Share this answer
 
v2
try like this

change form as ng-form and put in repeat tr like this

HTML
<tr ng-repeat="testing in $data "  name="editForm"  ng-form >




XML
</tr>


hope this help

regards,
yoyo
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900