question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unmaskAsNumber causing jquery serialize to fail

See original GitHub issue

using this options:

{
  alias: 'numeric',
  groupSeparator: '.',
  radixPoint: ',',
  autoGroup: true,
  digits: 2,
  digitsOptional: false,
  placeholder: '0',
  unmaskAsNumber: true,
  autoUnmask: true,
  removeMaskOnSubmit: true
}

calling jquery.serialize will throws exception saying that replace is not a function. this is because jquery serialize assume that the fields value is string and tries to escape new line characters if any.

https://jsfiddle.net/mtsunu/8Ldejeeq/

the other issue is when setting unmaskAsNumber: false. notice i’m using comma as radixPoint. when i input 12.000,24 the serialized value is 12000,24 (i’m guessing the unmask value will be wrong too, haven’t tried it though)

what is the correct options for that situation?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RobinHerbotscommented, Jun 3, 2016

@mtsunu ,

An example

Inputmask.extendAliases({
        "mynumeric": {
      alias: 'numeric',
      groupSeparator: '.',
      radixPoint: ',',
      autoGroup: true,
      digits: 2,
      digitsOptional: false,
      placeholder: '0',
      autoUnmask: true,
      removeMaskOnSubmit: true,
      onUnMask: function (maskedValue, unmaskedValue, opts) {
                if (unmaskedValue === "" && opts.nullable === true) {
                    return unmaskedValue;
                }
                var processValue = maskedValue.replace(opts.prefix, "");
                processValue = processValue.replace(opts.suffix, "");
                processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
                if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) 
             processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".");

                return processValue;
            },
    }
});

https://jsfiddle.net/8Ldejeeq/1/

0reactions
mtsunucommented, Jun 4, 2016

Okay. Maybe you should put a warning on the documentation.

Thanks for the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

serialize() form showing internal server error - Stack Overflow
I have a form, I am using serialize() to get the values from the form and post it in ajax. But I am...
Read more >
.serialize() | jQuery API Documentation
The .serialize() method creates a text string in standard URL-encoded notation ... and its children in a set will cause duplicates in the...
Read more >
'serialize' WITHOUT some form elements - MSDN - Microsoft
I have a form to submit via a JQuery function. Here is the function: function SubmitForm(form) { $.validator.unobtrusive.parse(form); var ...
Read more >
jQuery 1.4 $.param demystified - Ben Alman
And using jQuery's $.serialize method to convert form values into params for AJAX POST ... and attempting to do so may cause a...
Read more >
Adding additional Parameter in Serialize Form Data
Hi Guys, there are situations, when you have an Html form with some data in it and you have to submit the data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found