TextBox OnChanged event?

6 posts, 2 answers
  1. Vitalii
    Vitalii avatar
    104 posts
    Member since:
    Jul 2013

    Posted 12 Sep 2013 Link to this post

    It is possible to subscribe to OnChanged event, not to LostFocus? 

    The problem is quite obvious: it updates only on loosing focus.

    Problem reproduction:
    1. Move to Telerik Samples TextBox page
    2. Fill the form correctly: add name, username (it should be avaivable), email.
    3. Fill password with 7 symbols (it should be ok)
    Problem 1: once password contains 7 symbols, and it is still focused, the bottom button is still unavaivable
    4. Now, press Back key. "Sign up" is active now.
    5. Press on password, and delete 2-3 last symbols. Don't hide keyboard, "Sign up" button is accessible at this point (you can see top half of it).
    Problem 2, quite critical: "Sign up" is active and can be pressed even with empty password. And it shows "successful registration" for user with not valid password.


    Possible solution: use OnChanged event. Coding4fun using this approach:
    http://www.geekchamp.com/articles/talking-about-data-binding-in-wp7--coding4fun-textboxbinding-helper-in-depth

    <TextBox 
      Text="{Binding FooBar, Mode=TwoWay}" 
      local:TextBinding.UpdateSourceOnChange="True" /> 

  2. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 12 Sep 2013 Link to this post

    Hello Vitalii,

    Thank you for writing.

    You can subscribe to RadTextBox's TextChanged event and to RadPasswordBox's PasswordChanged event. We will make sure that we update our example before the next upload so that the validation is performed in time and users are not allowed to make a registration with invalid fields.

    I have updated your telerik points for your cooperation.
     
    Regards,
    Todor
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Vitalii
    Vitalii avatar
    104 posts
    Member since:
    Jul 2013

    Posted 12 Sep 2013 Link to this post

    Great! :)
  5. Vitalii
    Vitalii avatar
    104 posts
    Member since:
    Jul 2013

    Posted 03 Oct 2013 Link to this post

    Well.. but why it is called 2 times?

    Reproduction steps:
    1. Just open your RadTextBox sample 
    2. Add TextChanged Event to codebehind
    3. Add breakpoint inside
    4. Run and add text to the box

    Event would be called twice.


    EDIT: 
    also, there's some issues with binding.

    Added Mvvm Light's trigger
    telerikPrimitives:RadTextBox
                    x:Name="Address1TextBox"
                    Style="{StaticResource UserDetailsTextBoxStyle}"
                    Text="{Binding Address1, Mode=TwoWay}"
                    Header="{Binding Path=MainResources.Street_Address, Source={StaticResource LocalizedStrings}, Converter={StaticResource StringToStringWithAsterisk}}"
                    Watermark="{Binding Path=MainResources.Street_Address_sample, Source={StaticResource LocalizedStrings}}">
                     
                     
                     
                    <interactivity:Interaction.Triggers>
                        <interactivity:EventTrigger EventName="TextChanged">
                            <command:EventToCommand Command="{Binding OnTextChanged, Mode=OneWay}"/>
                        </interactivity:EventTrigger>
                    </interactivity:Interaction.Triggers>
                </telerikPrimitives:RadTextBox>
     
    //And in VM
     
    public RelayCommand OnTextChanged
            { get { return new RelayCommand(UpdateTextBoxesValidation); } }
     
    void UpdateTextBoxesValidation()
            {
                   if (String.IsNullOrEmpty(Address1)) // Breakpoint here. It is also called 2 times, and Address1 is always null. However, if to call this method non from this event, but manually (from appbar, for example), Address1 holds correct value.
                               int a = 1;
                    }
              }

  6. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 08 Oct 2013 Link to this post

    Hi Vitalii,

    We'll investigate the issue and get back to you as soon as possible. 

    Regards,
    Kiril Stanoev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  7. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 10 Oct 2013 Link to this post

    Hi Vitalii,

    Thank you for your patience.

    Our RadTextBox control inherits from the native TextBox control and we don't have control over the events that come from the native component. The first time TextChanged gets fired is the expected occasion when the text is changed. The second time is caused by the fact that we have another TextBox inside RadTextBox's template which is used for the view of RadTextBox when IsReadOnly is true and when IsEnabled is false. The second TextBox's Text property also changes since its data bound to the same value and also fires the TextChanged event which gets escalated to RadTextBox.

    The second issue is related to the fact that the binding gets evaluated only when the control loses focus. Since the initial value is empty, you always see that the value of Address1 is null. If you change the text, move the focus and get back to change the text again, you will see that the value of Address1 will not be null any more, but it will be the value of the text as it was when the control lost focus. Please note that this behavior is observed with the native TextBox control as well.

    You can have a look at these two forum posts: here and here. They both discuss options for applying validation without using code-behind.

    Don't hesitate to write us back if you need further assistance.

    Regards,
    Todor
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
DevCraft banner