0

I want to have a string that goes through angular's filter as a parameter for a javascript function. Angular doesn't parse it, how do I fix this?

<input type="text" ng-required="true" ng-model="foobar"
oninvalid="this.setCustomValidity({{ 'String' | myfilter }})">

The {{ .. }} does not go through Angular's parsing. If I remove the double quotation marks it still doesn't work as Angular 'fixes' it to be oninvalid="this.setCustomValidity("{{

Also, if there is another, more angular way of customizing the browser validation message, that would do the trick for me also.

2 Answers 2

0

You might want to read the angular documentation for input, in particular the example plunker provides the solution to your question.

If you still want a hint on what to do to use a filter in your argument please provide information about your oninvalid directive.

Sign up to request clarification or add additional context in comments.

2 Comments

Oninvalid is not my directive, but a HTML5 parameter for input field. When leaving a field empty that is 'required' (ng-required renders to both ng-required as well as required) then the browser displays it's own error, typically "Please fill out this field." The oninvalid -parameter is what the browser runs when the field is not a valid one. The attribute setCustomValidity is the javascript one to set the error value instead of "Please fill out this field." I need to localise this string, that is what the filter does.
I see, didn't understood your problem cause i didnt knew the html5 attribute behaviour. I now think that writing your own directive is the way to go to stay in the angular realm. As this seems to be a pretty standard use case, maybe you are lucky and find an existing directive at github / bower / npm. Also the answer to this related question stackoverflow.com/questions/17550836/… suggests that HTML5 validation isnt fully supported and you might be better off just disabling it and rolling your own with angular.
0

You can pass foobar directly

oninvalid="this.setCustomValidity({{ 'String' | myfilter(foobar) }})"

1 Comment

This is not what I asked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.