Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $compile to output html #184

Merged
merged 3 commits into from
Jan 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ You can also add a `validation-group` directive to group many elements into a gr
```html
<label>Validation group</label>
<!-- Group both of these elements inside the contact group -->
<input type="text" name="email" ng-model="email" validator="required" validation-group="contact">
<input type="text" name="email" ng-model="email" validator="required" validation-group="contact">
<input type="number" name="telephone" ng-model="telephone" validator="number" validation-group="contact">
<!-- The message will be placed in side the span element -->
<span id="contact"></span>
Expand Down Expand Up @@ -248,10 +248,14 @@ in `getDefaultMsg()`,and finally return the HTML code
$validationProvider.setErrorHTML(function (msg) {
// remember to return your HTML
// eg: return '<p class="invalid">' + msg + '</p>';
// or using filter
// eg: return '<p class="invalid">{{"' + msg + '"| lowercase}}</p>';
});

$validationProvider.setSuccessHTML(function (msg) {
// eg: return '<p class="valid">' + msg + '</p>';
// or using filter
// eg: return '<p class="valid">{{"' + msg + '"| lowercase}}</p>';
});
}]);
```
Expand Down Expand Up @@ -282,7 +286,7 @@ The built in `maxlength` and `minlength` validators use parameters to configure
<input type="text" name="username" ng-model="form.username" validator="maxlength=6"/>
```

You can use parameters in your custom validators in the same way.
You can use parameters in your custom validators in the same way.
You can access this parameter in the validation expression like so:

```html
Expand Down Expand Up @@ -358,5 +362,3 @@ angular.module('yourApp', ['validation'])
};
}]);
```


5 changes: 3 additions & 2 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
var $validationProvider = $injector.get('$validation');
var $q = $injector.get('$q');
var $timeout = $injector.get('$timeout');
var $compile = $injector.get('$compile');
var $parse = $injector.get('$parse');

/**
Expand All @@ -387,7 +388,7 @@
if (element.attr('no-validation-message')) {
messageElem.css('display', 'none');
} else if ($validationProvider.showSuccessMessage && messageToShow) {
messageElem.html($validationProvider.getSuccessHTML(messageToShow));
messageElem.html('').append($compile($validationProvider.getSuccessHTML(messageToShow))(scope));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be messageElem.append($compile($validationProvider.getSuccessHTML(messageToShow))(scope));?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step1: clear the output html => .html('')
Step2: append a new html element => .append(elm)

not a very smart solution but it have no other answers yet 💥

messageElem.css('display', '');
} else {
messageElem.css('display', 'none');
Expand Down Expand Up @@ -425,7 +426,7 @@
if (element.attr('no-validation-message')) {
messageElem.css('display', 'none');
} else if ($validationProvider.showErrorMessage && messageToShow) {
messageElem.html($validationProvider.getErrorHTML(messageToShow));
messageElem.html('').append($compile($validationProvider.getErrorHTML(messageToShow))(scope));
messageElem.css('display', '');
} else {
messageElem.css('display', 'none');
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/validator.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var $validationProvider = $injector.get('$validation');
var $q = $injector.get('$q');
var $timeout = $injector.get('$timeout');
var $compile = $injector.get('$compile');
var $parse = $injector.get('$parse');

/**
Expand All @@ -31,7 +32,7 @@
if (element.attr('no-validation-message')) {
messageElem.css('display', 'none');
} else if ($validationProvider.showSuccessMessage && messageToShow) {
messageElem.html($validationProvider.getSuccessHTML(messageToShow));
messageElem.html('').append($compile($validationProvider.getSuccessHTML(messageToShow))(scope));
messageElem.css('display', '');
} else {
messageElem.css('display', 'none');
Expand Down Expand Up @@ -69,7 +70,7 @@
if (element.attr('no-validation-message')) {
messageElem.css('display', 'none');
} else if ($validationProvider.showErrorMessage && messageToShow) {
messageElem.html($validationProvider.getErrorHTML(messageToShow));
messageElem.html('').append($compile($validationProvider.getErrorHTML(messageToShow))(scope));
messageElem.css('display', '');
} else {
messageElem.css('display', 'none');
Expand Down
Loading