[CLOSED] Getting the value from TextField with InputMask plugin

  1. #1

    [CLOSED] Getting the value from TextField with InputMask plugin

    Hi,

    I'm trying to read the value from the textfield with InputMask:

    X.TextFieldFor(x => x.Phone, false).Plugins(X.InputMask().Mask("(999) 99-99-99"))
    Resulting value (in form, in corresponding model and so on) has all special symbols from the mask like "-","(",")" etc. How to set the field value without it (but the user must see masked value!)?
    Last edited by Daniil; Sep 09, 2014 at 1:22 PM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi @centerinform,

    You can get unmasked value using this JavaScript code.
    App.TextField1.inputMask.getUnmaskedValue();
    Though, it might be problematic to get it automatically in a submitted data. How do you submit a form?
  3. #3
    Yes, the main problem is sending the form data. I submit it:

    App.Form1.getFieldValues()
    via the form action button (in the other place of code). Maybe, it's necessary to use some hidden field with the double-side sync?
  4. #4
    Then you could override the getModelData function.
    <ext:TextField runat="server" Note="(999) 999-9999" FieldLabel="Phone">
        <GetModelData Handler="var me = this,
                                   data = null;
                               if (!me.disabled && !me.isFileUpload()) {
                                   data = {};
                                   data[me.getName()] = me.inputMask.getUnmaskedValue(); //defaults to: data[me.getName()] = me.getValue();
                               }
                               return data;" />
        <Plugins>
            <ext:InputMask runat="server" Mask="(999) 999-9999" />
        </Plugins>
    </ext:TextField>
    See also
    http://docs.sencha.com/extjs/4.2.1/#...d-getModelData
  5. #5
    Hi Daniil,

    Overriding the GetModelData works but not in all cases. I also have the forms, where the dirtyChange event handler is using in order to watch out for any changes in the form, having been done by users. Applying the InputMask plugin, whereas the data is keeping in DB in unmasked view, makes the data "dirty". It makes semblance that user has changed the data. What can I do to make it works more correctly? (By the way, in the such forms I use GetSubmitData function overriding because GetModelData doesn't work because data is sent via "Send" button)
    Last edited by centerinform; Sep 03, 2014 at 8:00 AM.
  6. #6
    I see...

    It might be problematic to achieve that... I can suggest to try to use an additional Hidden field and load a database value to that Hidden field. Then synchronize the Hidden field with a TextField on client putting an unmasked value to the Hidden field and use it on submit. As for the TextField you can exclude it from submitting at all (SubmitValue="false"). Theoretically.
  7. #7
    Hi Daniil,

    Thank's a lot for your help. The problem has been solved with small improvements:

    	X.HiddenFor(x => x.Phone, false)
            .ID(id + "PhoneUnmasked")
            .Listeners(ls =>
            {
                ls.Change.Handler = "var fieldMasked = App." + id + "PhoneMasked; if (fieldMasked.inputMask.getUnmaskedValue() != this.getValue()) { fieldMasked.setValue(this.getValue()); fieldMasked.inputMask.validateMask(); }";
            }),
        X.TextFieldFor(x => x.Phone, false).DataIndex("PhoneMask")
            .ID(id + "PhoneMasked")
            .LabelAlign(LabelAlign.Top)
            .SubmitValue(false)
            .Listeners(ls =>
            {
                ls.Change.Handler = "var fieldUnmasked = App." + id + "PhoneUnmasked; if (fieldUnmasked.getValue() != this.inputMask.getUnmaskedValue()) { fieldUnmasked.setValue(this.inputMask.getUnmaskedValue()); }";
                ls.BoxReady.Handler = "if(this.mixins && this.mixins.field && typeof this.mixins.field['initValue'] == 'function') { this.mixins.field.initValue.apply(this); this.wasDirty = false; }";
            })
            .Plugins(X.InputMask().Mask("99-99-99"))
            .ColumnWidth(1)
            .LabelSeparator("")
    The code in the BoxReady Handler has been added for correct opening of the form with the self-made button for the data sending (the Phone field was considered to be "dirty" for some reason). I found this solution here: http://stackoverflow.com/questions/1...rm-dirty-state
  8. #8
    Thank you for sharing!

Similar Threads

  1. [CLOSED] TextField with Plugin CapsLockDetector
    By osef in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 01, 2013, 10:53 PM
  2. [CLOSED] InputMask plugin
    By luiz in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 26, 2013, 10:00 PM
  3. What values can I use in the InputMask Plugin?
    By KBorkiewicz in forum 2.x Help
    Replies: 2
    Last Post: Mar 26, 2013, 1:32 AM
  4. How to add an InputMask plugin?
    By joaxazevedo in forum 2.x Help
    Replies: 3
    Last Post: Feb 21, 2013, 8:28 PM
  5. Replies: 7
    Last Post: Dec 05, 2012, 6:11 AM

Tags for this Thread

Posting Permissions