Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9103277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:35:53+00:00 2026-06-17T01:35:53+00:00

A JSFiddle is here: http://jsfiddle.net/DfLdF/ The problem description is as follows, I have a

  • 0

A JSFiddle is here:

http://jsfiddle.net/DfLdF/

The problem description is as follows, I have a controller wrapping a form which contains some logic, and can not be defined within the directive hash as controller:

I need the ability to populate a field from a directive dynamically like so:

 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

I need the following to be fulfilled:

1) When the textfields value is changed, I want scope.fieldValue to be updated.
2) After this happens, I want the addValue method (defined on the wrapping controller), to be called with the new value for validation.
3) The addValue method should set the someAwesomeClass scope variable, and the input fields class should update.
4) The ngClasses to be applied are ng-valid/ng-invalid. Form validation should function correctly in correspondence with these classes

As can be seen in my jsfiddle, none of these things are currently happening, and I am unsure as to why…

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:35:54+00:00Added an answer on June 17, 2026 at 1:35 am

    You can fix it by defining a directive someClass, which will execute the function on its parent. The form tag gets an extra attribute execute, which holds the function to execute. The someClass directive will search the controller of dir directive (hence require: ‘^dir’) and execute it.

    Another solution would have been to drop the dir directive and define the execute attribute on the someClass directive (e.g. when each input field should trigger a different function).

    <form class="dir" execute="someFunction">
    

    Directives:

    app.directive('dir', function () {
      return {
        restrict: 'C',
        scope: {
          execute: '='
        },
        controller: function ($scope) {
          this.execute = $scope.execute;
        }
      };
    });
    
    
    app.directive('someClass', function () {
      return {
        restrict: 'C',
        require: '^dir',
        replace: true,
        template: '<INPUT name="foo" id="bar" type="text" ng-model="fieldValue" >',
        scope: {
          fieldValue: '@'
        },
        link: function (scope, elm, attrs, ctrl) {
          var monitorField = function (newValue, oldValue) {
            if (newValue) {
               ctrl.execute(newValue);
            }
          };
          scope.$watch("fieldValue", monitorField, true);
        }
      };
    });
    

    See jsFiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jsfiddle here: http://jsfiddle.net/aND4g/2/ I am having a problem with a text
I have a jsfiddle here http://jsfiddle.net/cbyJD/74 The problem I am having is that it
See JsFiddle here http://jsfiddle.net/WtgbV/2/ In words: I have some ajax call, and in the
I have a jsfiddle here - http://jsfiddle.net/9kKXX/20/ My jQuery function $(function() { $('form input[type=text]').live('keyup',
I have the problem built into a jsfiddle here: http://jsfiddle.net/XRdTD/ If you select something
I have some code in jsFiddle here: http://jsfiddle.net/xyuY6/ And the code: var App= {};
I have a jsfiddle here : http://jsfiddle.net/hhimanshu/eLhLS/1/ Current: On keypress, it keeps on appending
JSFiddle here: http://jsfiddle.net/xgTt2/3/ I have a $.each nested inside of a $.each , and
I have a jsfiddle here: http://jsfiddle.net/XM8hG/33/embedded/result/ To view code of fiddle click here: http://jsfiddle.net/XM8hG/33/
I have a jsfiddle here: http://jsfiddle.net/ybZvv/22/ The situation I have is that if you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.