Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unmaskAsNumber causing jquery serialize to fail #1288

Closed
mtsunu opened this issue May 31, 2016 · 7 comments
Closed

unmaskAsNumber causing jquery serialize to fail #1288

mtsunu opened this issue May 31, 2016 · 7 comments

Comments

@mtsunu
Copy link

mtsunu commented May 31, 2016

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?

@RobinHerbots
Copy link
Owner

@mtsunu ,

Maybe the unmaskAsNumber should return a numeric parsable string.

@mtsunu
Copy link
Author

mtsunu commented Jun 3, 2016

won't it be better to fix the custom radixPoint issue?

with the option named "unmaskAsNumber", it would make sense if we expect it to return a number rather than numeric string..

@RobinHerbots
Copy link
Owner

RobinHerbots commented Jun 3, 2016

The custom radixPoint issue is not really An issue as some backends want it that way to parse it correctly depending the culture settings. You can always extend the current implementation.

@RobinHerbots
Copy link
Owner

RobinHerbots commented 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/

@RobinHerbots RobinHerbots added this to the 3.4 milestone Jun 3, 2016
@mtsunu
Copy link
Author

mtsunu commented Jun 3, 2016

Thanks for the code.

I think you're right, I really need to fix my backend culture settings.
But what if I can't change my backend culture settings? Is that make sense?

So, have you decide what to do with unmaskAsNumber?

@RobinHerbots
Copy link
Owner

@mtsunu ,

unmaskedadnumber stays as is, also the unmasking.

When the culture setting of the backend are fixed, you can use the extension above. But I cannot think a reason why you could not change the culture settings on the backend.

@mtsunu
Copy link
Author

mtsunu commented Jun 4, 2016

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

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants