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

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

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

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.