1

I'm trying to write a small directive that will append the validation tags and ngMessages dynamically to the input. But I'm having trouble appending the ng-message attribute to the div.

The idea is to have this,

<div validator validations="{json_data containing error messages}">
  <input name='fieldName'>
</div>

Turned in to the following according to the provided JSON.

<div validator> 
  <input required="required"></input>
  <div ng-message="fieldName" ng-if="fieldName.$dirty>
    <p ng-message="required"> scope.message </p>
  </div>
</div>

I've currently managed to get the ng-required appeneded using the answer to this answer. But I can't seem to append the ng-message tag using the same technique. What should be done differently to solve this issue?

The final directive should be able to generate something like this Fiddle

The current version can be found in the Fiddle here the example works as expected until 'scope' is added. But as soon as 'scope' is added, the example stops working.

Update
I've realized that this only occurse when you add a local scope. This error doesn't occure when using the global scope and accessing the variable using scope.$eval(attrs.message)

Community
  • 1
  • 1
nipuna-g
  • 6,252
  • 3
  • 31
  • 48
  • Have you actually tried [angular-formly](https://github.com/formly-js/angular-formly)? if not - checkout, if yes - browser source code – Medet Tleukabiluly Feb 14 '16 at 10:30
  • @MedetTleukabiluly thank you for the quick reply. I have tried out angular-formly and found it to be really useful. But I'm doing the development for an organisation that prefers to have an in-house system. What do you mean by 'browser source code'? – nipuna-g Feb 14 '16 at 10:37

0 Answers0