Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Larry Qu asked in Javascript

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

Reply

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

Reply

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

Reply

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]... %>

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.