How can I remove AutoNumeric formatting before sub

2020-07-02 10:41发布

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.

9条回答
家丑人穷心不美
2楼-- · 2020-07-02 11:39

There is another solution for integration which doesn't interfere with your client-side validation nor causes the flash of unformatted text before submission:

var input = $(selector);
var proxy = document.createElement('input');
proxy.type = 'text';
input.parent().prepend(proxy);
proxy = $(proxy);
proxy.autoNumeric('init', options);
proxy.autoNumeric('set', input.val())''
proxy.change(function () {
    input.val(proxy.autoNumeric('get'));
});
查看更多
我命由我不由天
3楼-- · 2020-07-02 11:41

You can always use php str_replace function

str_repalce(',','',$stringYouWantToFix);

it will remove all commas. you can cast the value to integer if necessary.

查看更多
We Are One
4楼-- · 2020-07-02 11:42
$("input.classname").autoNumeric('init',{your_options});
$('form').submit(function(){
   var form=$(this);
   $('form').find('input.classname').each(function(){
       var self=$(this);
       var v = self.autoNumeric('get');
       // self.autoNumeric('destroy');
       self.val(v);
   });
});

classname is your input class that will init as autoNumeric Sorry for bad English ^_^

查看更多
登录 后发表回答