So based on the title, when should I do validation on a CEdit (textbox)?
所以基于标题,我什么时候应该在CEdit(文本框)上进行验证?
Background: I was transferred in a new dev group on our company, and their practice is pressing enter, that's when they do their validations on a CEdit (mfc dialog). Whereas I, came from .net, specifically from WinForms, where there are the Validated
and Validating
events, which every dev will see and realize that this is the correct event where you should do validation.
背景:我被转移到我们公司的一个新的开发小组,他们的实践是按下输入,那就是他们在CEdit(mfc对话框)上进行验证。而我来自.net,特别是来自WinForms,其中有Validated和Validating事件,每个开发人员都会看到并意识到这是您应该进行验证的正确事件。
My question in detail is:
我的问题详细是:
Should I follow their practice (pressing enter)? Or what I have in mind is using EN_KILLFOCUS
(which is close/related to the above events mentioned)? Or both are incorrect and is there an event much more suited for validation?
我应该遵循他们的做法(按回车)?或者我的想法是使用EN_KILLFOCUS(与上述事件关系/相关)?或两者都不正确,是否有更适合验证的事件?
I need your suggestions since if my co-devs are the ones to be asked, they'll all immediately say that I should handle validation upon pressing enter. Thank you!
我需要你的建议,因为如果我的共同开发人员被问到,那么他们都会立即说我应该按Enter键来处理验证。谢谢!
3 个解决方案
#1
1
Even in my company we have two parties.
即使在我的公司,我们也有两个派对。
1st party strictly says information is only validated when Enter is pressed, so in the moment when ALL information is available. Advantage if you have a bunch of information that influences each other this method is easy. The MFC DoDataExchange approach is their favorite.
第一方严格说信息仅在按下Enter时验证,因此在所有信息可用时。如果你有一堆相互影响的信息很容易,那么这种方法很有优势。 MFC DoDataExchange方法是他们的最爱。
2nd party says: information must be validated as early as possible. I think this approach is ok when each value is nearly independent. In this case you check all data upon EN_CHANGE or EN_KILLFOCUS and disable the OK button until all data is valid.
第二方说:信息必须尽早验证。我认为当每个值几乎独立时,这种方法是可行的。在这种情况下,您将检查EN_CHANGE或EN_KILLFOCUS上的所有数据,并禁用“确定”按钮,直到所有数据都有效。
Negative to the second method is that you have to give more information to the user in the moment when data is entered, to guide him to correct the data. The first method may explain the problem in one error message.
第二种方法的不利之处在于,您必须在输入数据时向用户提供更多信息,以指导他更正数据。第一种方法可以在一个错误消息中解释该问题。
I use both methods in my programs. And in most cases we use the 1st method, because we found out, that a comprehensive error message with detailed information is easier to maintain and to understand by users, as when they see a dialog an can't get to an enabled OK button...
我在我的程序中使用这两种方法。在大多数情况下,我们使用第一种方法,因为我们发现,具有详细信息的全面错误消息更易于维护和用户理解,因为当他们看到对话框时无法获得启用的OK按钮。 ..
BTW: I hate dialogs where I can enter negative numbers, where only positive numbers are allowed. Always use the correct and best input fields you can get to allow the best guidance. So the MFC method saying "Out of range" after pressing enter is not a good solution. If you have a minimum and a maximum you can even correct the value directly after the user gave the input.
顺便说一句:我讨厌可以输入负数的对话框,其中只允许正数。始终使用您可以获得的正确和最佳输入字段,以获得最佳指导。因此按下输入后MFC方法说“超出范围”不是一个好的解决方案。如果您有最小值和最大值,您甚至可以在用户输入后直接更正该值。
But this answer and the question tends to be opinion based.
但这个答案和问题往往是基于意见的。
#2
0
Whatever you decide to do, you should try to minimize any disruption of the work flow for your users. And, at the same time, you need to be consistent with what the user has come to expect for validation behavior. Don’t let your bias impact the dialog behavior in a way that causes the user confusion, or, extra time working with the dialog. The most important thing to keep in mind is to be consistent with whatever approach you take.
无论您决定做什么,都应该尽量减少对用户工作流程的干扰。而且,与此同时,您需要与用户对验证行为的期望保持一致。不要让您的偏见以导致用户混淆的方式影响对话行为,或者使用对话框的额外时间。要记住的最重要的事情是与你采取的任何方法保持一致。
#3
-1
1) MFC provides validation facility for many of the data types. It depends on the type of the data you want to enter in that control. Is this possible use this facility?
1)MFC为许多数据类型提供验证工具。它取决于您要在该控件中输入的数据类型。这有可能使用这个设施吗?
In my opinion, EN_KILLFOCUS is a better option because how will validate if the user doesn't press enter and presses tab to move on to the next control? You can still discuss this with your peers and conclude which is a better place to handle the validation.
在我看来,EN_KILLFOCUS是一个更好的选择,因为如何验证用户是否没有按Enter键并按Tab键继续下一个控件?您仍然可以与同行讨论这个问题并得出结论哪个是更好的处理验证的地方。
#1
1
Even in my company we have two parties.
即使在我的公司,我们也有两个派对。
1st party strictly says information is only validated when Enter is pressed, so in the moment when ALL information is available. Advantage if you have a bunch of information that influences each other this method is easy. The MFC DoDataExchange approach is their favorite.
第一方严格说信息仅在按下Enter时验证,因此在所有信息可用时。如果你有一堆相互影响的信息很容易,那么这种方法很有优势。 MFC DoDataExchange方法是他们的最爱。
2nd party says: information must be validated as early as possible. I think this approach is ok when each value is nearly independent. In this case you check all data upon EN_CHANGE or EN_KILLFOCUS and disable the OK button until all data is valid.
第二方说:信息必须尽早验证。我认为当每个值几乎独立时,这种方法是可行的。在这种情况下,您将检查EN_CHANGE或EN_KILLFOCUS上的所有数据,并禁用“确定”按钮,直到所有数据都有效。
Negative to the second method is that you have to give more information to the user in the moment when data is entered, to guide him to correct the data. The first method may explain the problem in one error message.
第二种方法的不利之处在于,您必须在输入数据时向用户提供更多信息,以指导他更正数据。第一种方法可以在一个错误消息中解释该问题。
I use both methods in my programs. And in most cases we use the 1st method, because we found out, that a comprehensive error message with detailed information is easier to maintain and to understand by users, as when they see a dialog an can't get to an enabled OK button...
我在我的程序中使用这两种方法。在大多数情况下,我们使用第一种方法,因为我们发现,具有详细信息的全面错误消息更易于维护和用户理解,因为当他们看到对话框时无法获得启用的OK按钮。 ..
BTW: I hate dialogs where I can enter negative numbers, where only positive numbers are allowed. Always use the correct and best input fields you can get to allow the best guidance. So the MFC method saying "Out of range" after pressing enter is not a good solution. If you have a minimum and a maximum you can even correct the value directly after the user gave the input.
顺便说一句:我讨厌可以输入负数的对话框,其中只允许正数。始终使用您可以获得的正确和最佳输入字段,以获得最佳指导。因此按下输入后MFC方法说“超出范围”不是一个好的解决方案。如果您有最小值和最大值,您甚至可以在用户输入后直接更正该值。
But this answer and the question tends to be opinion based.
但这个答案和问题往往是基于意见的。
#2
0
Whatever you decide to do, you should try to minimize any disruption of the work flow for your users. And, at the same time, you need to be consistent with what the user has come to expect for validation behavior. Don’t let your bias impact the dialog behavior in a way that causes the user confusion, or, extra time working with the dialog. The most important thing to keep in mind is to be consistent with whatever approach you take.
无论您决定做什么,都应该尽量减少对用户工作流程的干扰。而且,与此同时,您需要与用户对验证行为的期望保持一致。不要让您的偏见以导致用户混淆的方式影响对话行为,或者使用对话框的额外时间。要记住的最重要的事情是与你采取的任何方法保持一致。
#3
-1
1) MFC provides validation facility for many of the data types. It depends on the type of the data you want to enter in that control. Is this possible use this facility?
1)MFC为许多数据类型提供验证工具。它取决于您要在该控件中输入的数据类型。这有可能使用这个设施吗?
In my opinion, EN_KILLFOCUS is a better option because how will validate if the user doesn't press enter and presses tab to move on to the next control? You can still discuss this with your peers and conclude which is a better place to handle the validation.
在我看来,EN_KILLFOCUS是一个更好的选择,因为如何验证用户是否没有按Enter键并按Tab键继续下一个控件?您仍然可以与同行讨论这个问题并得出结论哪个是更好的处理验证的地方。