PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Input mask validation clears content on invalid input

  1. We have a text field with an input mask of:
    99 9999 9999

    However, we have found that if the user doesn't complete the whole thing (so for example types 07 3333 3) it will clear the content of the whole field during validation. Is there any way to prevent this? Our client would like users to see the data they previously entered.

    Cheers,
    Emu

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  2. If the input does not match the mask, the field will become blank after you tab or click off it. How can the data be submitted and fail validation if it's not there after you exit the field?

    Can you post a link to your form please? With all those numbers being required, I can't see how you could submit less than that in the first place, and what the validation error would be if you did submit the whole thing (other than the field being required.) Something does not make sense to me and I will need more information from you please.

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  3. Please see http://anmfsa.emu.com.au/contact-us/ and the "Phone" field.

    Essentially what we would expect to happen is if the validation fails, for the data the user entered to still be there so that they can adjust it accordingly. At this moment it will clear the "Phone" field of data if the user attempts to submit and the data is invalid.

    Cheers,
    Emu

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  4. I see your form. When I enter incomplete data in the phone field, and tab off the field, my input disappears immediately. That is how the input mask script works. If I submit the form, I am submitting with nothing in the phone number field because the data is not accepted as soon as I tab off the field to go on to the next. Does that make sense? When it fails validation, it's because there was nothing entered in the phone field at all, because the incomplete number was never accepted in the field in the first place.

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  5. I understand, but is there a way to turn that functionality off? I am inclined to agree with our client in that it is a little annoying for the user. For example, if they accidentally don't hit a key correctly and then tab out of the field it clears everything. I would expect it to just show an error.

    Cheers,
    Emu

    Posted 11 years ago on Tuesday January 22, 2013 | Permalink
  6. Otherwise if you could please let me know how else to perform validation on content, happy to use that instead.

    Cheers,
    Emu

    Posted 11 years ago on Tuesday January 22, 2013 | Permalink
  7. If your client does not like the functionality of the input mask script, I think it would be best to not use it at all, and then just validate the input. You can use the gform_validation filter to check the input against your own mask, and return an error if the input does not match. Here is how to use gform_validation: http://www.gravityhelp.com/documentation/page/Gform_validation

    Looking over the documentation of the masked input script, I don't see a way to modify the way it works to meet your needs: http://digitalbush.com/projects/masked-input-plugin/

    Posted 11 years ago on Monday January 28, 2013 | Permalink