Set a InputMask in code behind

  1. #1

    Set a InputMask in code behind

    Dear friends,

    How i can set a inputmask for a field in code behind, using a conditional string to set a different inputmask for each case?

    Exemple:

    String TipoPessoa = "";
    
    if (TipoPessoa=="j")
    {
        InputMask = "99.999.999/9999-99";
    }
    else
    {
        inputMask = "999.999.999-99";
    }
    Thanks in advance,

    Gustavo Coelho
    Last edited by fabricio.murta; Jul 26, 2016 at 8:39 PM.
  2. #2
    Hello!

    Just an idea. Instead of changing the input mask, you can use binding and only show the corresponding masked field depending on the "tipo pessoa" chosen.

    In this example, it just sets the 'disabled' status of a field. It could pretty much set the 'hidden' status of two fields as well.
    Data binding - Component state.

    If you still want to dynamically set input mask, there are some threads covering this subject in the forums already, just search for dynamically change inputmask and you should get good threads.

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thanks for your help!



    I searched the forum for dynamic input mask and found the ability to set the mask as follows:

    In Client:
    <ext:TextField ID="fldCnpjCpf" runat="server" FieldLabel="CNPJ / CPF" LabelAlign="Top" Width="180" MarginSpec="0 10 0 0">
        <Plugins>
            <ext:InputMask ID="InputMaskCNPJ" runat="server" Mask="" InvalidMaskText="Formato incorreto"/>
        </Plugins>
    </ext:TextField>
    In Server:
    if (cbxTipoPessoa.Text == "F") {
        InputMaskCNPJ.Mask = "999.999.999-99";
    }
    else
    {
        InputMaskCNPJ.Mask = "99.999.999/9999-99";
    }
    
    fldCnpjCpf.Focus();
    Last edited by fabricio.murta; Jul 26, 2016 at 8:38 PM.
  4. #4
    Hello @GugaSoft!

    Glad you could find a solution that better fit your needs! And thanks for sharing the outcome!

    Notice I edited both your posts to wrap code blocks inside [code][/code] tags and indented stuff a litte. It makes it so much nicer to read and understand the code, don't you agree?
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] InputMask plugin
    By luiz in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 26, 2013, 10:00 PM
  2. [CLOSED] InputMask JS error
    By stratadev in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 13, 2013, 4:27 PM
  3. Disabling InputMask using JS
    By joaxazevedo in forum 2.x Help
    Replies: 1
    Last Post: Mar 06, 2013, 3:17 PM
  4. [CLOSED] InputMask
    By sigmasafi in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Feb 28, 2013, 4:08 AM
  5. How to add an InputMask plugin?
    By joaxazevedo in forum 2.x Help
    Replies: 3
    Last Post: Feb 21, 2013, 8:28 PM

Posting Permissions