MaskedTextInput With Literals

4 posts, 0 answers
  1. Mike Kacos
    Mike Kacos avatar
    28 posts
    Member since:
    Sep 2009

    Posted 16 Jul 2014 Link to this post

    <telerik:RadMaskedTextInput x:Name="rmeSolicitationNumber"  Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="19,39,0,0" Width="200" Mask="SPAAAA-AA-A-AAAA" Text="{Binding SolicitationNumber, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnNotifyDataErrors=False, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"  Style="{StaticResource RadMaskedTextBoxStyle}" SelectionOnFocus="SelectAll"   TextMode="MaskedText" InputBehavior="Replace"  />
    I have the above MaskedTextInput and I'm having some problems with it.  As you can see I'm binding to the Text attribute as opposed to value, because we need to save the literals ("SP") to the database.  I thought all was well, until I try to bring data back from the database.  When I do a select and display values from the database back into the control, nothing appears at all.  I then added a second binding to the Value attribute (Both bound to the exact same values) I got data to display, BUT what happens is the value gets pushed out and truncated.  Meaning a value entered as "SP1234-56-R-7890" and stored in the database as "SP123456R7890 (We do strip out the dashes when saving) appears as "SPSP12-34-5-6R78"

    The display of the value coming back from the database is the issue.  Please help me see what I'm doing wrong.

    Thanks!
    -Mike
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 18 Jul 2014 Link to this post

    Hi Mike,

    Please let me first make a quick clarification - you should consider the Text property as only a getter, setting or binding the Text won't change the Value property. Text is just the string you see as a combination of the properties Value, Placeholder, TextMode, Mask. So the preferred approach is to bind the Value property only and add the dashes manually when saving into the db / remove when loading from Db (this could be performed in Converter). It is also expected that the string "SP123456R7890" will be inserted from left to the right on the available positions marked with the mask symbol "A". "A" allows both numeric and  alphabetic symbols. If the requirement is to use only digits for these positions, you can consider using  Mask="SP####-##-#-####". Please let us know if this is what you needed.

    Regards,
    Petar Mladenov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
  4. Mike Kacos
    Mike Kacos avatar
    28 posts
    Member since:
    Sep 2009

    Posted 21 Jul 2014 in reply to Petar Mladenov Link to this post

    Thanks for the reply.  Would it be possible to add a boolean or some other attribute which would allow the Value property to get the literals of the mask?  I believe this is the way the old MaskedTextbox worked, and this behavior is preferable to us.  Also to be able to set a value and have the control overwrite the mask as well.  Meaning if I bring back SP123456R7890 from the database, the control would realize SP is in the mask so the control would display correctly as opposed to doubling the "SP".  Again I believe this is the way the old MaskedTextBox worked.

    Thanks.

  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 22 Jul 2014 Link to this post

    Hello Mike,

    The Value property is designed to contain what you type or pass but without the Mask symbols. We added the Text property in the MaskedInput controls to separate this scenarios and to have a property which contains the Mask symbols. Yes, this is different than the old MaskedTextBox's behavior but makes the internal logic simpler and easy to maintain. Please have in mind that the old control used to have plenty of bugs related to databinding and did not support null values. To support mask symbols in the Value, this would require too much code for something that can be easily solved with Converters on an application level.
    However, your requirement is similar to the following feature request and you can vote for it in order to increase its development priority.

    Regards,
    Petar Mladenov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top