Here is a JSFiddle link for reference:
The issue I am facing involves a controller wrapping a form with certain logic that cannot be defined within the directive hash as a controller. Specifically, I need to dynamically populate a field from a directive in the following manner:
App.Directive.SomeAwesomeDirective = ->
restrict: 'C'
link: (scope, element, attrs) ->
someValue = scope.someValue
field = element.find(".some-class")
scope.fieldValue = someValue
field.ngModel = "scope.fieldValue"
field.ngClass = "scope.someAwesomeClass"
monitorFields = (newValue, oldValue) ->
console.log "we are here"
console.debug newValue
console.debug oldValue
scope.addValue(newValue)
scope.$watch "scope.fieldValue", monitorFields, true
The requirements for this task include:
1) Updating scope.fieldValue when the textfield's value is changed. 2) Triggering the addValue method (defined on the wrapping controller) to validate the new value once it has been updated. 3) The addValue method should set the someAwesomeClass scope variable and update the input field's class accordingly. 4) Applying ng-valid/ng-invalid classes for proper form validation based on the aforementioned conditions.
The current jsfiddle demonstration does not exhibit the desired behavior, and I am seeking assistance in resolving this issue...
Thank you!