branko
branko

Reputation: 43

formly validation message with angularjs 1.2

I am trying to add validation message for required input field with angularjs 1.2. All examples I have found so far refer to angular > 1.2 and use ng-messages. I tried getting formControl and check form object but it is empty. This is my attempt:

        formlyConfig.setWrapper({
          name: 'validation',
          types: ['input'],
          templateUrl: 'my-messages.html'
        });
        formlyValidationMessages.addStringMessage('required', 'This field is required');

and in custom validation template:

    <script type="text/ng-template" id="my-messages.html">
      <formly-transclude></formly-transclude>
            {{ options }}
    </script>

The output is like:

{"templateOptions":{"required":true,"label":"Surname"},"type":"input","modelOptions":{"updateOn":"blur"},"key":"surname","extras":{},"data":{},"validation":{"messages":{},"errorExistsAndShouldBeVisible":false},"id":"sectionForm_input_surname_0","name":"sectionForm_input_surname_0","initialValue":"ffdsffdsfdsgds","formControl":{}}

so, formControl is empty object. errorExistsAndShouldBeVisible has appropriate value, it is set to true if field is empty, but messages are always empty object.

Appreciate any help

Upvotes: 0

Views: 176

Answers (1)

MattE
MattE

Reputation: 1114

This may be a dumb question, but why are using an old version of angular that has numerous issues that have been fixed since? My advice would be to upgrade your version of angular.

Upvotes: 0

Related Questions