0

I have a group of textbox on which I configured an autoNumeric (this plugin: https://github.com/autoNumeric/autoNumeric ):

$("input[name$='something']").autoNumeric('init', {aSep: '.', aDec: ',', aSign: ' €', vMax: '99999999999.9999'});

When I post my form I want to reformat the values on the textbox:

function parseBeforeSubmit() {
    $("input[name$='something']").val(function(){
                                                    var myText = $(this)[0];
                                                    return myText.autoNumeric('get');
                                                });
}

obviously I cant get it working, what I'm seeing is that myText has a property called jQuery36000058939066319538821 which contains autoNumeric, but it seems strange that I can't dynamically access the autoNumeric component and also it seems this autoNumeric component doesn't contains the unformatted numeric value.

Sure there's something I'm missing or maybe I used the wrong approach?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Stefano Vercellino
  • 353
  • 1
  • 6
  • 17
  • Can you please post the plugin reference? – Irvin Dominin Jun 15 '22 at 10:01
  • in the js i found: @version: 1.9.26 - 2014-10-07 GMT 2:00 PM, i'll add to the post – Stefano Vercellino Jun 15 '22 at 10:04
  • What is the expected format you want to set while calling parseBeforeSubmit? Are you trying to remove the separators and currency from the number? – Alexandru Severin Jun 15 '22 at 10:12
  • Can you post a sample on jsfiddle or something similar? – Irvin Dominin Jun 15 '22 at 10:13
  • Ok I digged a bit more, since I'm on a large project I just used autoNumeric on examples taken from others pages, but I have discovered that what I'm realling using is a specific implementation of autoNumeric: https://github.com/autoNumeric/autoNumeric now I'm trying to understand if maybe this specific implementation provides some method to handle more autoNumeric in a single declaration. I also prepared this fiddle: https://jsfiddle.net/8u1kcsjo/ – Stefano Vercellino Jun 15 '22 at 10:55
  • Yes, i wanted to remove separators and currency without losing decimals, I know It will be easier removing them as strings but seemed more "correct" to use autoNumeric to parse the values – Stefano Vercellino Jun 15 '22 at 10:59

1 Answers1

0

First and foremost, the call you are doing in your example are for v1.9.*, which is deprecated. If you can, you should use the latest version 4.6.0, which is much more user friendly, and have no jQuery dependency.

If you want to modify the form input value before submitting, take a look at the specific form functions in the official documentation.

Perhaps you'll need formNumericString(), formArrayNumericString() or formJsonNumericString, depending of your exact need.

Alex
  • 1,241
  • 13
  • 22