0

I am doing a dynamic form validation as follows:

<form role="form" name="myForm">
    <div class="row" ng-repeat="field in fields">
        <div class="form-group">
            <input type="text" class="form-control" placeholder="{{field.title}}" name="formData[field.name]" ng-model="formData[field.name]" required ng-minlength=5 ng-maxlength=20>
            <div class="error">
                <small class="error" ng-show="myForm.formData[field.name].$error.minlength">
                    {{field.minValidationMessage}}
                </small>
            </div>
        </div>
    </div>
    ...
</form>

my controller is as follows:

    $scope.fields = [{
    name: 'name',
    title: 'Name',
    placeholder: 'Enter product name',
    ...
    },{
    name: 'code',
    title: 'Code',
    placeholder: 'Enter product code',
    ...
    }]

    $scope.formData = {
    name: '',
    code: ''
 };

Here the following code is not working:

<small class="error" ng-show="myForm.formData[field.name].$error.minlength">
    {{field.minValidationMessage}}
</small>

However without ng-repeat(static) it is working as follows:

<small class="error" ng-show="myForm.code.$error.minlength">
    Your name is required to be at least 3 characters
</small>

How to refer myForm.formData[field.name] in ng-show.

Thanks in advance.

Mahendran
  • 2,191
  • 5
  • 24
  • 40
  • Field name on input and that on validation do differ, they should be same – harishr Dec 11 '14 at 02:16
  • @harish corrected the input as `formData[field.name]` which is a typo. But the original reported issue still exist. – Mahendran Dec 11 '14 at 03:22
  • have a look at [here](http://stackoverflow.com/questions/14378401/dynamic-validation-and-name-in-a-form-with-angularjs), dynamic field names are not supported in angular – harishr Dec 11 '14 at 04:21

0 Answers0