ValidationState not response properly

8 posts, 2 answers
  1. bento
    bento avatar
    35 posts
    Member since:
    Aug 2013

    Posted 23 Sep 2013 Link to this post

    Hi,

    I use these code but ValidationState text not response properly. When I type below 5 chars, text alert correctly, but more than that debug using breakpoint run well but text alert display still "Password too short". It should be, the next text but not shown. Can you try it ?

    Thanks

    private void textPassword_PasswordChanged(object sender, EventArgs e)
     {
         if (textPassword.Password.Length < 5)
         {
             isPasswordValid = false;
             textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Password too short!");
         }
         else if (!InputForm.IsPassword(textPassword.Password))
         {
             isPasswordValid = false;
             textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Use 1 uppercase, number & special char!");
         }
         else if (textPassword.Password.Length >= 5 && InputForm.IsPassword(textPassword.Password))
         {
             isPasswordValid = true;
             textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Valid, "");
         }
     }
  2. MasterChiefMasterChef
    MasterChiefMasterChef avatar
    152 posts
    Member since:
    Jan 2013

    Posted 23 Sep 2013 Link to this post

    Hi bento,

    I would love to figure out why your PasswordBox is not vaidating correctly. Can you provide more code so that I can run your example? I would need the InputForm class so I can check your InputForm.IsPassword method. Let me know if this is possible!

    Master Chief
  3. DevCraft banner
  4. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 24 Sep 2013 Link to this post

    Hi Benyamin,

    Thank you for writing.

    The reason for this behavior is that the method ChangeValidationState is expected to work to actually change the validation state which in your case is already Invalid and doesn't need changing. In order to be able to use the Invalid state with more than one message you need to change the validation state, before you check the password's length:

    private void textPassword_PasswordChanged(object sender, EventArgs e)
    {
     
        textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.NotValidated, string.Empty);
     
        if (textPassword.Password.Length < 5)
        ....
    }

    This way each time the text is changed the password box will be initially in the correct NotValidated state and you will be able to change it after you perform your validation.

    Let us know if you need further assistance.
     
    Regards,
    Todor
    Telerik
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  5. bento
    bento avatar
    35 posts
    Member since:
    Aug 2013

    Posted 24 Sep 2013 Link to this post

    Hi Master Chief sorry for late reply, but thanks. 
    Hi Todor, yes it is works.

    Now I have new issue, sometimes screen freeze when Password and Retype Password events fired several times on textchanged. I'll post the code later. I need to recreate the sample first and test it on new project to make sure. Fyi I use Lumia 920 with Amber for device test. 
  6. Todor
    Admin
    Todor avatar
    778 posts

    Posted 27 Sep 2013 Link to this post

    Hi Benyamin,

    If you confirm that there is an issue, don't hesitate to write back with more information. It would be best if you open a new support ticket to attach a project that we can use to reproduce your issue, since attachments are not permitted in forum posts.
     
    Regards,
    Todor
    Telerik
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  7. bento
    bento avatar
    35 posts
    Member since:
    Aug 2013

    Posted 27 Sep 2013 Link to this post

    Hi Todor,

    I've created a copy portion of my code... here is... on my Lumia 920, please help to analyze and here the step :

    1. type a password any length on "Password" box (first box) 
    2. Press Peek Button to see password
    3. Screen freeze... Can press back button to hide keyboard, or use Win Button only.

    <phone:PhoneApplicationPage x:Class="RadPasswordBox.MainPage"
                                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                                xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                                xmlns:telerikPrimitives="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Primitives"
                                shell:SystemTray.IsVisible="True">
        <StackPanel x:Name="ContentPanel">
            <telerikPrimitives:RadPasswordBox Name="textPassword"
                                              Watermark="Password"
                                              BorderBrush="Peru"
                                              BorderThickness="0,0,1,2"
                                              MaxLength="25"
                                              PasswordChanged="textPassword_PasswordChanged" />
            <telerikPrimitives:RadPasswordBox Name="textRetypePassword"
                                              Watermark="Retype Password"
                                              BorderBrush="Peru"
                                              BorderThickness="0,0,1,2"
                                              MaxLength="25"
                                              PasswordChanged="textPassword_RetypePasswordChanged" />
        </StackPanel>
    </phone:PhoneApplicationPage>


    using System;
    using Microsoft.Phone.Controls;
    using RadPasswordBox.Resources;
    namespace RadPasswordBox
    {
        public partial class MainPage : PhoneApplicationPage
        {
            public MainPage()
            {
                InitializeComponent();
            }
            private void textPassword_PasswordChanged(object sender, EventArgs e)
            {
                textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.NotValidated, string.Empty);
     
                if (textPassword.Password.Length < 5)
                {
                    textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Password too short!");
                }
     
                if (textPassword.Password != textRetypePassword.Password)
                {
                    textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.NotValidated, string.Empty);
                    textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Password not match.");
                }
                else
                {
                    textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.NotValidated, string.Empty);
                    textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Valid, "");
                }
            }
            private void textPassword_RetypePasswordChanged(object sender, EventArgs e)
            {
                if (textRetypePassword.Password != textPassword.Password)
                {
                    textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Password not match.");
                }
                else if (textRetypePassword.Password == textPassword.Password)
                {
                    textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Valid, "");
                }
            }
        }
    }

  8. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 02 Oct 2013 Link to this post

    Hi Benyamin,

    This is a very strange issue which is related to the focusing of the elements. We will need more time to investigate it deeper and find a way to avoid the freeze. For now you can use the following workaround:

    <StackPanel x:Name="ContentPanel">
        <ContentControl HorizontalContentAlignment="Stretch">
            <telerikPrimitives:RadPasswordBox Name="textPassword"
                                    Watermark="Password"
                                    BorderBrush="Peru"
                                    BorderThickness="0,0,1,2"
                                    MaxLength="25"
                                    PasswordChanged="textPassword_PasswordChanged" />
        </ContentControl>
        <ContentControl HorizontalContentAlignment="Stretch">
            <telerikPrimitives:RadPasswordBox Name="textRetypePassword"
                                    Watermark="Retype Password"
                                    BorderBrush="Peru"
                                    BorderThickness="0,0,1,2"
                                    MaxLength="25"
                                    PasswordChanged="textPassword_RetypePasswordChanged" />
        </ContentControl>
    </StackPanel>

    Simply place the password boxes inside content controls and the freeze will be avoided.
     
    Regards,
    Todor
    Telerik
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  9. bento
    bento avatar
    35 posts
    Member since:
    Aug 2013

    Posted 02 Oct 2013 Link to this post

    Thanks Todor, freeze is gone for now...
Back to Top
DevCraft banner