Validation issue with existing orders after quantity rule updates

Forums Min Max Default Quantity for WooCommerce Validation issue with existing orders after quantity rule updates

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #172909
    Alessio
    Participant

    Hello team,

    I’m experiencing a validation issue in the WooCommerce back-end that prevents me from saving existing orders. The error occurs after updating product quantity rules (min/max) with your plugin.

    <b>Problem Description:</b> When attempting to update an old order that does not comply with the new quantity rules, the browser displays an HTML5 validation error:

    An invalid form control with name='order_item_qty[86]' is not focusable.

    This happens because the order item quantity fields (<input type="number">) have min or max attributes that are incompatible with the current value. Concurrently, these fields are rendered as “not focusable,” likely due to CSS or JavaScript.

    The browser blocks the form submission because it cannot focus the field to show the user the error, effectively preventing any changes to the order from being saved.

    I’ve noticed a setting in your plugin called “Replace woocommerce quantity field template.” It appears that when this option is disabled, native browser validation takes over, causing this conflict.

    Could you provide a solution or a patch to fix this issue? A possible solution might be to either disable HTML5 validation on the order edit form or to handle the validation with JavaScript even when the “Replace woocommerce quantity field template” option is turned off.

    Thank you for your support.

    Best regards,

    Alessio

    #172913
    Alessio
    Participant

    I’m writing to provide an update on the order validation issue I reported. I found a temporary solution that unblocks order saving, and I wanted to share it with you.

    The problem stems from the browser’s native HTML5 validation on HPOS order edit pages. It triggers on <input type="number" /> fields with values that don’t conform to the min, max, or step rules set by your plugin. Because the fields are also “not focusable,” the browser completely blocks the save process.

    To work around this, I’ve injected a JavaScript script that removes the validation attributes from the quantity fields when the <b>”Update”</b> button is clicked. I added this code to my functions.php file to ensure it only runs on order edit pages:

    <hr />

    function fix_quantity_validation_issue() {
    $is_wc_order_page = (isset($_GET['page']) && $_GET['page'] === 'wc-orders' && isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id']));
    
    if (!$is_wc_order_page) {
    return;
    }
    
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
    $('.save_order').on('click', function(e) {
    $('input.quantity[type="number"]').each(function() {
    $(this).removeAttr('min');
    $(this).removeAttr('max');
    $(this).removeAttr('step');
    });
    });
    });
    </script>
    <?php
    }
    add_action('admin_footer', 'fix_quantity_validation_issue');

    <hr />

    This solution allows me to save existing orders and confirms that the issue is a client-side validation conflict, not a back-end error. I hope this helps you in developing a permanent patch for your plugin.

    Thanks again for your support.

    Best regards,

    Alessio

    • This reply was modified 4 months, 2 weeks ago by Alessio.
    • This reply was modified 4 months, 2 weeks ago by Alessio.
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.