Code Monkey home page Code Monkey logo

Comments (6)

danhunsaker avatar danhunsaker commented on August 20, 2024

What does the console show? This looks like it should work...

from angular-dynamic-forms.

shuffledex avatar shuffledex commented on August 20, 2024

I was very sure this line made the necessary to compile the input: $compile(newElement)($scope)

The input rendered is: < input type="text" name="text" ng-model="stdFormData['text']" ng-required="true" placeholder="text" own-validator="something" required="required" >

Te console output when I try to write something into the input:

TypeError: Cannot set property 'text' of undefined
at D.assign (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:73:448)
at td.$setViewValue (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:140:392)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:113:26
at Object.$get.e.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:89:39)
at Object.$get.e.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:89:146)
at HTMLInputElement.h (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:113:6)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:24:155
at Array.forEach (native)
at m (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:6:192)
at HTMLInputElement.c (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:24:126)

from angular-dynamic-forms.

danhunsaker avatar danhunsaker commented on August 20, 2024

That looks like you don't have a text key in your form's model...

from angular-dynamic-forms.

shuffledex avatar shuffledex commented on August 20, 2024

What do you mean? the ng-model is dynamically generated... so when I write the first time, the ng-model has not yet setting the key? and this is why the directive brokes? How can I solve it?

from angular-dynamic-forms.

danhunsaker avatar danhunsaker commented on August 20, 2024

It's entirely unrelated to your directive. When your form is built, the ng-model of the <dynamic-form> tag is used to define an object model, which then contains the various form elements' models as keys - submodels, if you will. In this case, that means $scope.stdFormData needs to have a text property defined in your controller: $scope.stdFormData.text = null; That should fix the error you're seeing at the moment.

As to your directive, if you're looking to get updates when the input value changes, you'll need to set up a watcher on the model. There might be a better hook you could use, depending on what you're aiming to do; check the Angular docs, or do a web search for validation directives, for more info on what to do with your directive here.

from angular-dynamic-forms.

danhunsaker avatar danhunsaker commented on August 20, 2024

@shuffledex - Have you figured this one out? I was mistaken a few comments prior to this one: it's not that you didn't have a text key on your form model, but rather that you hadn't defined your form model within the form's $scope. You'll need to be sure you include $scope.stdFormData = {}; in your controller - setting $scope.stdFormData.text would require you to do that first anyway, but isn't necessary in itself.

from angular-dynamic-forms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.