title: SYMFONY FORM isClicked() issue (depending Browser) when mixed with JavaScript - JQuery: event.preventDefault() and event.target.submit()
body: <p><strong>The goal:</strong> </p>
  
  <p>I want on a Symfony FORM to have <strong>two submit buttons</strong>. 1st one would be used to validate the form, the <strong>2nd submit button would be used to get away from the form</strong>.</p>
  
  <p>By default the fields of the form use the <code>required</code> check before submitting, which means that prior to use the 2nd Submit, the <code>required</code> attributes need to be turned off on DOM <code>&lt;input&gt;</code>. I do that by using some JQuery, <code>event.preventDefault()</code>, I turn off the <code>required</code> on each <code>&lt;input&gt;</code> and then do an <code>event.target.submit()</code>.</p>
  
  <p>Then on my Symfony side I expect to catch the button that had been clicked by using the <code>$form-&gt;has([button name])-&gt;isClicked()</code> function.</p>
  
  <p><strong>The issue:</strong></p>
  
  <p>I have noticed that depending on the browser, the $form->has([button name])->isClicked() doesn't work if some JavaScript with <code>event.preventDefault()</code> and <code>event.target.submit()</code> had been used.</p>
  
  <p>On chrome (Version 51.0.2704.103 m) I get (isClicked = 1 or true):
  <a href="https://i.stack.imgur.com/Vh6Z8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vh6Z8.jpg" alt="enter image description here"></a></p>
  
  <p>On firefox (Version 47.0) or Microsoft EDGE 25.* I get (isClicked = false):
  <a href="https://i.stack.imgur.com/SakZe.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SakZe.jpg" alt="enter image description here"></a></p>
  
  <p><strong>The code:</strong></p>
  
  <p><a href="https://github.com/nyluje/symfony_form_test_isclicked" rel="nofollow noreferrer"><strong>The full code is at the following github</strong></a>.</p>
  
  <p><em>Emphasis on the code:</em></p>
  
  <p>In /src/AppBundle/Form/FormType.php you'll find, the code that manages the JavaScript to hold on the <code>Submit</code>, turnoff the <code>required</code> and resume the <code>Submit</code>:</p>
  
  <pre><code>  public function buildForm(FormBuilderInterface $builder, array $options)
    {
  
      $builder
      -&gt;add('field1',EmailType::class, array('label'=&gt;'Form Field 1'))
      -&gt;add('submit',SubmitType::class,array('label'=&gt;'Submit Form'))
    -&gt;add('get_away_from_form',SubmitType::class,array(
      'label'=&gt;'Get away from form',
      'attr'=&gt;array(
      'onclick'=&gt;'{
        //IF THE USER CLICK THE NOT_SUBMIT BUTTON THE REQUIRED FIELD ARE DISABLED BEFORE THE SUBMIT HAPPENS
       // Here is the part where are done (see GITHUB code for details): 
       ////`event.preventDefault()`,
       //// turn off the `required` on each `&lt;input&gt;`
       //// and then do an `event.target.submit()`.
  
      }'
      )
      ));
    }
  </code></pre>
  
  <p>In /src/AppBundle/Controller/DefaultController.php you'll find, the check on $form->get('get_away_from_form')->isClicked():</p>
  
  <pre><code>    if($form-&gt;isSubmitted() &amp;&amp; $form-&gt;has('get_away_from_form')){
          if($form-&gt;get('get_away_from_form')-&gt;isClicked() == 1){
              $isClicked = 'It works as expected: $form-&gt;get(get_away_from_form)-&gt;isClicked() = '.$form-&gt;get('get_away_from_form')-&gt;isClicked();
          } else {
              $isClicked = 'It DOESN\'T work as expected: $form-&gt;get(get_away_from_form)-&gt;isClicked() = '.$form-&gt;get('get_away_from_form')-&gt;isClicked();
          }
      }
  </code></pre>
  
  <p>Anyone has an idea?</p>