jugglervr
jugglervr

Reputation: 165

Trouble defining custom Parsley validation in AngularJS

I've inherited a project that uses Laravel and nodejs to run an angularjs app (right?)

The app makes extensive use of parsley validators, but I need one that validates against a typeahead list.

I just can't seem to figure out where to insert this validation code. It doesn't run anywhere I stick it. I can access window.Parsley from the console, and it shows that I've registered the custom validator. and when I spam the custom validation declaration around to try to get it picked up, I get an warning that it's already been decalred, but it won't run on my form.

My thought was that I'd need to add the custom validator code right after I populate my data object with an API call, but that's not working.

Just trying to get the example to work at first

<input type="text" autocomplete="off" class="form-control" placeholder="Search Client" data-ng-model="addexpense.model.client" uib-typeahead="clientObj.name as clientObj.name for clientObj in addexpense.getClientList($viewValue)" data-parsley-palindrome="" uib-typeahead-min-length="2">

and

window.Parsley.addValidator('palindrome', {
    validateString: function(value) {
        console.log("whee")
        return value.split('').reverse().join('') === value;
    },
    messages: {
        en: 'This string is not the reverse of itself',
        fr: "Cette valeur n'est pas l'inverse d'elle même."
    }
});

I expect the validator to run on the field I have attached it to, but it's not running at all, despite being registered with window.Parsley. I'm suspecting that there's somewhere special to declare the custom validator in AngularJS, but I'm worried about needing to pass it the list of validations (though I guess I could run another API call from wherever I can get the validator to work)

Upvotes: 1

Views: 110

Answers (0)

Related Questions