Skip to main content

After I submit(click) the form(submit input tag), the submit tag become disabled, how can I avoid this?

Javascript • Asked by Larry Qu

The purpose is add product to cart, target is blank.

After I submit(click) the form(submit input tag), the submit tag become disabled, how can I avoid this?
I need it is always enabled for click.

part of products#index html

<div class="product">
            <div class="product-info product-name">土豆</div>
            <div class="product-info product-description">个大,均匀,甘甜。</div>
            <div class="product-info product-price">¥2.5/ 斤</div>
            <div class="product-info">
    <%= form_for(@cart, namespace: @product.id, target: "_blank") do |f| %>
        <%= f.hidden_field :product_id, value: @product.id, namespace: @product.id %>
        <% if current_user %>
        <%= f.hidden_field :user_id, value: current_user.id, namespace: @product.id %>
        <% end %>

        <div><%= f.number_field :amount, min: 1, max: 100, value: 1, required: true,  namespace: @product.id %> 斤</div>
        <div><%= f.submit "加入购物车", class: 'btn btn-primary' %></div>
    <% end %>
            </div>
</div>

application.js

$(document).on('turbolinks:load', function() {
    $('input[type=submit]', this).attr('disabled', false)
    $(".new_cart").attr({
        target: '_blank'
    });

});

This video show the problem


If im understanding correctly, just delete this: data-disable-with="Add to Cart"


after delete this: data-disable-with="Add to Cart", still not work.


Try changing the "Add to Cart" "button" so it's not an input field. Try making it a submit button (e.g., "<%= f.submit .... [ whatever else ] ... %>") or just a button <%= f.button "Add to Cart" .... [whatever else]... %>


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.