Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirm is flickering

I am trying to add a confirm on 1 event , it is working on firefox but not on chrome , earlier it was working on chrome as well but now not.

Now the confirmation box comes but soon it disappears, it flickers.

Below is the code for this:

$('.job_form').on('submit', function(e) {
    if (!confirm("If this job is posted to more than 1 person, it will go to the first person that accepts it.")) {
      e.preventDefault();
      return false;
    }
});
<%= form_with(model: job, html: {"data-parsley-validate" => '', class: 'job_form'}, local: true) do |f| %>
  //  html fields
  <%= render partial: 'form2', locals: {f: f} %>
<% end %> 

Below is form2

//html fields
<div id="isAllDiv"></div>

<div class="col-md-12 text-center">
 <%= f.submit 'Post Job', class: 'btn btn-primary signin-btn' %>

//html code with other fields

Output of executing $._data( $(".job_form")[0], "events" );

* {submit: Array(2), click: Array(1)}
    * click: Array(1)
        * 0:
            * data: undefined
guid: 19
handler: ƒ (t)
                * guid: 19
arguments: (...)
caller: (...)
length: 1
name: ""
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: parsley.min.self-78b…b2ddab.js?body=1:17
[[Scopes]]: Scopes[3]

            * namespace: "Parsley"
needsContext: false
origType: "click"
selector: "input[type="submit"], button:submit"
type: "click"
__proto__: Object

        * delegateCount: 1
length: 1
__proto__: Array(0)

    * submit: Array(2)
        * 0:
            * data: undefined
guid: 18
handler: ƒ (t)
namespace: "Parsley"
needsContext: undefined
origType: "submit"
selector: undefined
type: "submit"
__proto__: Object

        * 1:
            * data: undefined
guid: 42
handler: ƒ (e)
namespace: ""
needsContext: undefined
origType: "submit"
selector: undefined
type: "submit"
__proto__: Object

        * delegateCount: 0
length: 2
__proto__: Array(0)

    * __proto__:
        * constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
            * arguments: (...)
caller: (...)
length: 0
name: "valueOf"
__proto__: ƒ ()
[[Scopes]]: Scopes[0]

        * __defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()

like image 709
Chakreshwar Sharma Avatar asked Jul 16 '19 13:07

Chakreshwar Sharma


Video Answer


1 Answers

Try by removing the e.preventDefault() or return false from the submit function. You cannot use it together

$('.job_form').on('submit', function(e) {
    if (!confirm("If this job is posted to more than 1 person, it will go to the first person that accepts it.")) {
      e.preventDefault()
    }
});
like image 184
Aniket Tiwari Avatar answered Sep 24 '22 04:09

Aniket Tiwari