balthazar / ng-markdown

:memo: [DEPRECATED] Markdown directive for AngularJS
http://apercu.github.io/ng-markdown/
MIT License
12 stars 1 forks source link

associate with model #3

Closed ralyodio closed 10 years ago

ralyodio commented 10 years ago

I'm getting an error trying to associate the editor with a model:

<ng-markdown content="newJob.description" ng-model="newJob.description"></ng-markdown>
Error: [$compile:multidir] Multiple directives [ngModel, ngModel] asking for 'ngModel' controller on: <textarea ng-model="newJob.description content" msd-elastic="\
\
\
" content="newJob.description">
http://errors.angularjs.org/1.3.0-build.2860+sha.85f8b65/$compile/multidir?p0=ngModel&p1=ngModel&p2='ngModel'ontroller&p3=%3Ctextarea%20ng-model%3D%22newJob.description%content%22%20msd-elastic%3D%22%5C%0A%5C%0A%5C%0A%22%20content%3D%22newJob.description%22%3E

Here is my original HTML, trying to make editor work:

            <div class="form-group" ng-class="{ 'valid': form.description.$valid && submitted,
                                          'invalid': form.description.$invalid && submitted }">
                <label>Job Description</label>

                <textarea name="description" class="form-control" ng-model="newJob.description"
                       placeholder="Enter job description..." ng-minlength="4" required mongoose-error></textarea>

                <!--<div class="wmd-button-bar"></div>-->
                <!--<ng-markdown content="newJob.description" name="description" ng-model="newJob.description"></ng-markdown>-->
                <!--<div class="wmd-preview"></div>-->

                <p class="help"
                   ng-show="(form.description.$error.minlength || form.description.$error.required) && submitted">
                    Job description must be at least 60 characters.
                </p>

                <p class="help" ng-show="form.description.$error.mongoose">
                    {{ errors.description }}
                </p>
            </div>
balthazar commented 10 years ago

To bind a value with the directive, you only need the content attribute, so remove the ng-model one.

ralyodio commented 10 years ago

When I submit the form, that field is empty.

balthazar commented 10 years ago

Okay I see, I will create a new release this night or tomorrow to fix the problem, bad choice to not use the ng-model at first, sorry for that

ralyodio commented 10 years ago

also, it would be cool if I could add some attributes for the generated <textarea> as you can see in my original, I have a few angular boolean attributes like placeholder="Enter job description..." ng-minlength="4" required mongoose-error. I need to surface these errors back to the field in which the data is collected.

Thanks a bunch. I like your editor, took me awhile to find it.

ralyodio commented 10 years ago

Apercu, thanks, what about passing extra attributes to the <textarea>? Angular has a lot of nifty form handling logic that I'd like to take advantage of.

balthazar commented 10 years ago

Since the textarea replace the markdown markup, each attribute is copied, I've tested it using the placeholder one, and I also remember to have seen every class relative to form validation like ng-dirty.

Have you some particular environnement that could break this logic ?

balthazar commented 10 years ago

Sorry, the issue was automatically closed since I've deploy the new release to the master branch, let me know if you have still the problems.

ralyodio commented 10 years ago

Works like a charm now. thank you.