Giter Club home page Giter Club logo

Comments (8)

smurugavel avatar smurugavel commented on June 29, 2024

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.

freemng avatar freemng commented on June 29, 2024

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.

smurugavel avatar smurugavel commented on June 29, 2024

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.

idreeshaddad avatar idreeshaddad commented on June 29, 2024

@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.

freemng avatar freemng commented on June 29, 2024

Thanks @idreeshaddad and @smurugavel
It's work~

from xtform.

iviamontes avatar iviamontes commented on June 29, 2024

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.

idreeshaddad avatar idreeshaddad commented on June 29, 2024

@iviamontes Yes, you are correct, thank you for noting that.

from xtform.

iviamontes avatar iviamontes commented on June 29, 2024

Thank to you for your work.

from xtform.

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.