This is a migrated thread and some comments may be shown as answers.

Switching ValidationStates

1 Answer 74 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vitalii
Top achievements
Rank 2
Vitalii asked on 03 Oct 2013, 11:41 AM
So, i'm doing field check in the VM, and send message with status to the View. 
However, when i'm having different Invalid messages, they are not having effect for the field message (probably due to optimization).

Sample:
                    switch (_results.ZipStatus)
                    {
                        case 0: // Ok
                            ZipTextBox.ChangeValidationState(ValidationState.Valid, "Ok");
                            break;
                        case 1: // String is empty
                            ZipTextBox.ChangeValidationState(ValidationState.Invalid, "Cant be empty");
                            break;
                        case 2: // String.Count != 5
                            ZipTextBox.ChangeValidationState(ValidationState.Invalid, "Should be Zip"); 
                            break;
                    }

If user enters nothing, it would be 1 case, and he would get "Cant be empty" message.
Then, if he would enter 2 digits, it would be 2 case, but he would still see "Cant be empty" message.
Then, if to enter 5 digits, it would be 0 case, he would see "Ok" message;
Then, if to enter 2 digits again, it would be 2 case, and now user would see "Should be Zip" message.

As mentioned before, i assume, it is caused by optimization (if still Invalid state, dont change message), but with this scenario, it is working wrong. I guess, workaround is just to set it to ValidationState.Validating before switching.

1 Answer, 1 is accepted

Sort by
0
Vitalii
Top achievements
Rank 2
answered on 03 Oct 2013, 12:12 PM
Yep, now its ok

                    ZipTextBox.ChangeValidationState(ValidationState.Validating, String.Empty);
                    switch (_results.ZipStatus)
                    {
                        case 0: // Ok
                            ZipTextBox.ChangeValidationState(ValidationState.Valid, "Ok");
                            break;
                        case 1: // String is empty
                            ZipTextBox.ChangeValidationState(ValidationState.Invalid, "Cant be empty");
                            break;
                        case 2: // String.Count != 5
                            ZipTextBox.ChangeValidationState(ValidationState.Invalid, "Should be Zip"); 
                            break;
                    }
Tags
TextBox
Asked by
Vitalii
Top achievements
Rank 2
Answers by
Vitalii
Top achievements
Rank 2
Share this question
or