Comments (8)
I could not see custom validation working so I added my own method to make it work.
it is easy.. just add your method in xtFormConfig provider and call it in your controller.
from xtform.
Thanks for your reply, Vel
However, I have still no much idea on adding my method to xtFormConfig after I review the example and the js file.
Do you mind show me some hints on how can I add the method and use it ?
Many thx.
from xtform.
Hey freemng,
that was quite a hack.. I added a new method in xtFormConfig provider service which is a replica of xtFormConfig.setErrorMessages, (xtFormConfig's private function)
this method should be placed inside this.$get.
Then, I call this method from my controller. function has a single json parameter and json looks similar to _errors.
Remember to instantiate / inject "xtFormConfig" in your controller to take advantage of your new method.
does this help?
thanks
Vel.
from xtform.
@freemng you can create a custom validator directive, add it to the xtForm module, and broadcast the XtForm.ForceErrorUpdate event.
The directive:
angular.module('xtForm')
.directive('exactWordValidator', function () {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
var isValid = function (value) {
return (!value || value === attrs.exactWordValidator);
};
ngModel.$parsers.unshift(function (value) {
var valid = isValid(value);
ngModel.$setValidity('exactWordValidator', valid);
scope.$broadcast('XtForm.ForceErrorUpdate', null, 'submit');
return valid ? value : undefined;
});
}
};
});
The view:
<input id="exactWord" name="exactWord" type="text" placeholder="Must be the word 'hello'" ng-model="exactWord" exact-word-validator="hello" msg-exact-word-validator="word must be 'hello'">
<xt-validation-inline for="exactWord"></xt-validation-inline>
@refactorthis Should this be added to the example page?
from xtform.
Thanks @idreeshaddad and @smurugavel
It's work~
from xtform.
hmm, I think you need to change
$scope.$broadcast('XtForm.ForceErrorUpdate', null, 'submit');
for
scope.$broadcast('XtForm.ForceErrorUpdate', null, 'submit');
I just removed the $.
from xtform.
@iviamontes Yes, you are correct, thank you for noting that.
from xtform.
Thank to you for your work.
from xtform.
Related Issues (20)
- CSS styles required for red borders are not documented HOT 1
- seperate tooltip element HOT 3
- translations HOT 5
- Tooltip hover behaviours HOT 4
- $validators HOT 1
- bower install not working HOT 4
- inline validation doesn't work correctly with dynamic id's HOT 2
- fix code for minification HOT 1
- How to use the pattern type for xtFormValidationInline HOT 2
- xtForm + jasmine
- Custom strategy for validation errors on form load
- it's 2015
- xtForm and UI Bootstrap $apply already in progress HOT 3
- Tooltips does not hide when I hit browser back button HOT 2
- Add main file to bower.json
- Problem with the validation
- Tooltips left behind HOT 2
- Does not work with nested ng-form
- Installation documentation incorrect HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xtform.