Search code examples
javascriptjqueryjquery-pluginsautonumeric.js

How can I remove AutoNumeric formatting before submitting form?


I'm using the jQuery plugin AutoNumeric but when I submit a form, I can't remove the formatting on the fields before POST.

I tried to use $('input').autonumeric('destroy') (and other methods) but it leaves the formatting on the text fields.

How can I POST the unformatted data to the server? How can I remove the formatting? Is there an attribute for it in the initial config, or somewhere else?

I don't want to send the serialized form data to the server (with AJAX). I want to submit the form with the unformatted data like a normal HTML action.


Solution

  • I wrote a better, somewhat more general hack for this in jQuery

    $('form').submit(function(){
        var form = $(this);
        $('input').each(function(i){
            var self = $(this);
            try{
                var v = self.autoNumeric('get');
                self.autoNumeric('destroy');
                self.val(v);
            }catch(err){
                console.log("Not an autonumeric field: " + self.attr("name"));
            }
        });
        return true;
    });
    

    This code cleans form w/ error handling on not autoNumeric values.