How can I remove AutoNumeric formatting before submitting form?

后端 未结 11 2963
栀梦
栀梦 2021-02-19 05:26

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\

11条回答
  •  执念已碎
    2021-02-19 06:18

    Solution for AJAX Use Case

    I believe this is better answer among all of those mentioned above, as the person who wrote the question is doing AJAX. So kindly upvote it, so that people find it easily. For non-ajax form submission, answer given by @jpaoletti is the right one.

    // Get a reference to any one of the AutoNumeric element on the form to be submitted
    var element = AutoNumeric.getAutoNumericElement('#modifyQuantity');
    
    // Unformat ALL elements belonging to the form that includes above element
    // Note: Do not perform following in AJAX beforeSend event, it will not work
    element.formUnformat();
    
    $.ajax({
        url: "",
        data : {
            ids : ids,
            orderType : $('#modifyOrderType').val(),
            
            // Directly use val() for all AutoNumeric fields (they will be unformatted now)
            quantity : $('#modifyQuantity').val(),
            price : $('#modifyPrice').val(),
            triggerPrice : $('#modifyTriggerPrice').val()
        }
    })
    .always(function(  ) {
        // When AJAX is finished, re-apply formatting    
        element.formReformat();     
    });
    

提交回复
热议问题