-
Notifications
You must be signed in to change notification settings - Fork 176
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
Add support to onboard error message explicitly. #125
Comments
I have provide a pull request about this feature. |
The "invalidCallback" can not perform this feature well. Since the validations invoked from back-end, we can't make sure the label messages, besides, it should be handled globally,developers don't want to setup invalidCallback for every inputs. |
Hi @tshi0912 You can use config to define your Is this the one you mentioned? |
看了下代码,估计invalidCallback还是做不到的,我的目标是能将后台返回的错误消息设置到相应的控件上(以Angular Validation插件应有的方式),invalidCallback只是提供了一个回调点,其他的功能,譬如显示提示label啥的都没有。 |
是指需要用到 ajax 嗎,然後回傳 response 的資料? |
是的,通过ajax由后端返回某种格式的对象,然后前端检查格式对象中的返回码,譬如code==2,代表返回的是验证错误,则其中的数据对象包含了错误文本数组,通过调用$validationProvider.showErrors(form, data.fieldErrors);显示。 |
那你可以用 因為 angular-validation 已經幫你做好 promise 的部分,你只要回傳 |
(⊙o⊙)…额,你还是没明白我的意思。$validationProvider.showErrors(form, data.fieldErrors);这样的API是用来统一处理验证异常的。也就是所有的后端验证错误都是通过统一调用一次这个API就全部处理掉了。因为在我的程序里面,不管前端做不做校验,后端还是全部要再做一遍的,他不是处理单个验证逻辑,也不是用定义表达式或校验规则的方式就能搞定的。这是一种普适的处理,对ajax返回的结果进行统一监控处理,如果发现是验证出错,则定位到具体的表单,将错误文本按字段反馈到不同的input控件中。 |
Since you are doing backend validation, why do you need to do again the client-side validation? Are you really need that? |
It's not re-validating on client-side. It just feed back the errors (which produced by back-end validations) into client-side input controls. |
Good, your concern is right. I have saw your code
You just want to check the specific form but not trigger from the submit? Am I right? |
Yes, you got it. |
Unfortunately, you cannot check the form valid without submitting first. |
Open it if you have any question. 🍻 |
Sometimes the Form is validated by server side, they just want flow the error messages into the form fields.That's it. |
I'm trying to rethink about this feature now. |
This kind of feature is really useful, since the validation always need to be taken on both client & server side. |
@tshi0912 is right. I have the same issue. |
Hi @boiawang Do you mind showing us your case, i need more use case to define the spec of using this feature. |
举个栗子: 修改密码,服务端返回原密码错误,然后我想把错误显示在密码框下面,这种用setExpression是不能实现的 |
我在想的是,因為其實這也是 validate 的功能,只是不要把錯誤訊息顯示出來。是不是有什麼比較好的方式可以達到同樣效果。 |
@huiei90 yeah! |
@boiawang 請問你的例子中,為何 “错误显示在密码框下面” 不行呢? 這個錯誤顯示是指後段傳回的錯誤訊息嗎? |
I know this is an old question, but I was wondering if there was any update to this. In our use case we are implementing a feature to sign up for our site. We have a email text box, and after pressing the submit button we check on the server side if the email already exists. If it does exist we need to return a message that says 'Email already in use'. This message ideally would appear under the email text box. Do you have a suggestion on how to implement this? |
Hi huei90,
First of all, thanks to provide so useful validation module in angular world. I like it very much.
It's powerful to validate the form input, textarea and select control in client side, but it's only in client side.
In many cases, we want to provide a consolidated way to feed back the error messages from server side validation to the specific form controls, say, validate whether the userName is duplicated and show the "user name xxx is occupied" label beside the userName input. Since the validation is occurred on server side, we can't pre-define the errors in front-end rules. So if the module provide such a API
It will be very helpful. Hence we can config the consolidated error/exception handling in angular config:
The text was updated successfully, but these errors were encountered: