-
Notifications
You must be signed in to change notification settings - Fork 399
Form Validation and ngMessages Issues #283
Comments
I just watched the egghead.io video on validation and it does appear that the Still trying to nail down the first two issues. |
Sorry I haven't responded until now. Been kinda drowning recently. I'm not certain what the problem is. Why don't you have a look at this example and see if you can get it working. |
No worries. Will do, thanks. |
So here's something interesting with that Codementor example and I can reproduce it in a Plunker. The Chrome console is throwing an error when focus is gained and then lost on the IP Address field. Text doesn't even have to be entered. Not sure if this is a bug in Angular or Formly, but Angular is trying to call setAttribute() on a comment tag:
I'll keep moving forward using the Codementor example. |
Ah, the problem is actually a jqLite bug that has been fixed in 1.4.x and I don't expect will be backported to 1.3.x :-( angular/angular.js#11038 The only way to accomplish the ng-repeat with ng-messages is to use 1.4.x or include jQuery |
Cool, thanks for following up on that. We're currently using (but probably don't need to be) full jQuery so that alleviates that issue. I've been working on this problem all morning and it does not appear that, at least in my plunker setup, I can use both default messages in my
If I get rid of the default messages in On a whim, I updated the plunker to angular 1.4 RC1 and I get a different error which actually makes sense:
It appears that it's trying to bind the I'm ok for now in just using the default values in my I'll wait for you to respond before closing. Thanks. |
Oh, sorry, I thought you were talking about overriding messages set in the formlyValidationMessages service. Yeah, simply using the template wont work, but that's not a formly thing, that's an ng-messages thing. If you want defaults, use the formlyValidationMessages service. This is why you generally don't want to have any custom I'll have to look at making sure everything works ok in angular@1.4.x. I was under the impression that it did, but I'll double check that. Thanks! |
Good deal, thanks. |
I'm trying to get my head wrapped around this stuff as I've never used ngMessages before and combining it with custom validation has me out of my element. I've glued together stuff from the formly custom validation example (http://angular-formly.com/#/example/advanced/validators) and the advanced angular workshop you gave at the SLC ng-conf (I think it was called angular-formly-convert or something):
I've set this up in a plnkr: http://plnkr.co/edit/84hhADDgsLAIdU7eKsCM
First, If I uncomment the
validation
item, I get the following error in the console because the first item being inserted into themessages
array isundefined
- I'd like to be able to override the default if necessary:My understanding from http://docs.angular-formly.com/v5.2.1/docs/formly-form is that
validation.messages
keys map to the default messages I've defined in myngMessages
template.Second, the first time the form loads, if I enter an invalid pattern, and the field loses focus, the field is marked with an error, but no error message is displayed. If I refocus the field, remove the text, and lose focus again, the error messages display correctly (both the required and validation).
Third, the keys of the
validators
object is the name of the validator. It sounds like this can be anything so long as it's not a pre-existing validator name? (Per theValidator as an object
section of the aforementioned docs page). The example the formly site uses isipAddress
but if I change my example'susername
topattern
, I get additional errors.The text was updated successfully, but these errors were encountered: