-
Notifications
You must be signed in to change notification settings - Fork 291
ngMessages support #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ngMessages support #132
Conversation
Yeah! This is a perfect fit. The docs even say that you should use it for displaying form validation errors. One problem however remains, look at this example: http://djangular.aws.awesto.com/classic_form/ I really like that idea. |
I've added an ngMessages page to the example. At this point it's only using both model and form validation like the 'Combined Validation' page. There are also a couple of things to note:
EDIT with the reintroduction of the valid message, there's a drop of 41.
EDIT Just realised the project i'm working on is using 0.7.3, i'm going to update tomorrow and take a look at the new field_mixins module.
|
…on the fields $message object - this allows for multiple binded validators
…to prevent NgModelFoermMixin rejected error from being included
I'd like to propose a change to the way that field.$message works when using ngMessages. This would allow multiple validators on the same field to bind to a specific message. I don't think this is a breaking change, as it'll only affect people who opt to use ngMessages. As this is field specific, an an individual field would only ever be handled by 1) the existing method (assign error string directly to $message) or 2) the proposed method for compatibility with the new 1.3 validators (assign error string to a related property on $message). There will be no crossover even if a dev decides to validate different forms with different methods. e.g For 'rejected' errors you'd bind to field.$message.rejected This validator specific property can then be used by the validator to check if it has as error. |
Hi James, |
why did you close this? |
|
Hi Jacob, i'm not sure i understand what docs you need from me? Would you like me to write docs which explain how to use the ngMessages functionality or docs that explain the code for you? |
Docs which explain it to the end user. These are also very helpful for me. BTW, I've never used ngMessages, so I have no clue how they work. Is ist correct, that ngMesages is available only for Angular>1.3? But another consideration. Django has a messaging framework. Wouldn't it make sense to combine them? Django messages are rendered statically, and remain on the page, until it is reloaded. |
Hi Jacob, i've added docs to explain the usage, let me know what you think? Yes, they only work with 1.3+, so this would need to be a separate (opt in) module that's not minified with the rest. The name follows the trend of angular naming conventions, in that it's slightly misleading. I can see the logic, as you could essentially use them to monitor key/value pairs on any object, but as their primary use seems to be responding to the
RE: django messages, i'm actually working on an angular ajax solution for this at the moment. |
@jamesbrobb As I currently have no use for it (and btw. busy on something else), would you like to maintain this additional functionality now and in the future? I then would give you write access to the repository. This also means, that you bear some responsibility for the estim. >1000 users of this project. @dasf |
I don't really know |
@jrief Sorry for the delay in my response, thanks, i'd be very happy to maintain this feature. I've finished adding docs and unit tests for both the client and backend. I have one small issue to resolve and then it should be good to go. |
@jrief I'm just working on getting this to work when submitting the classic form and model form via POST, but have noticed an issue with the classic form. There's an Does there also need to be the same directive for a EDIT I've added the suggested fix to my working copy and it fixes the issue i've described without breaking any tests |
So this is pretty much done, although it may require a few tweaks depending on your thoughts regarding #160 and my 2nd point below. A couple of things to note:
I spent a bit of time trying to get it to work with both the 'Classic Subscription' and 'Model Scope' forms (with #160 being the result of that process). It's doable, but will involve a bit of extra work, but i'm not sure it's worth the effort. I started on it but then came to the conclusion that it probably wasn't necessary for those forms, as its purpose is to manage the display of 'validation' messages. Which don't occur on either of them. I'd be interested to hear what you think?
|
Hi, Regards, |
If we add ngMessages support to django-angular, the minimum required version of Angular will be 1.3. Everybody whom I asked told me that they had no problem so far with 1.3. |
I really like this feature even if I'm not using (yet) ngMessage. @jamesbrobb has done an amazing job! We should merge it very soon. I thought we were just waiting for the PR#160 to merge this one. |
I really did not have time to dig into this PR although this looks very 2015-07-10 19:29 GMT+02:00 Adrien Brunet [email protected]:
|
As a workaround, I can double all {% field.error %} and put it in both 2015-07-11 14:04 GMT+02:00 Alexandre Desenfant <
|
@jamesbrobb finally merged! Thanks and sorry for the long delay. I ran into an issue with your unit tests. Please check the file |
👍 Well done @jrief! |
Hi Jacob, i've just updated my forms to use ngMessages and was wondering if it's something you think would be useful for the project?
It adds a better flow for dealing with server errors, using a 'rejected' validator to display a returned field error. Plus there's also a significant reduction in watchers. I have 3 forms with a total of 9 fields and have seen a reduction of 40.
One thing to note is that ngMessages are dependent on angular 1.3+
The new logic consists of:
A new TupleErrorList - NgMessagesTupleErrorList
A django filter to add the validator to the input - although there might be a better solution for this?
An angular service to process and apply the errors
An angular 'rejected' validator directive
Anyway, let me know what you think?