1414use Ecommit \UtilBundle \Helper \UtilHelper ;
1515use Symfony \Component \Form \FormView ;
1616use Symfony \Component \OptionsResolver \OptionsResolver ;
17+ use Twig_Environment ;
1718
1819class JqueryHelper
1920{
@@ -23,13 +24,20 @@ class JqueryHelper
2324 */
2425 protected $ util ;
2526
27+ /**
28+ * @var Twig_Environment
29+ */
30+ protected $ templating ;
31+
2632 /**
2733 * Constructor
2834 * @param UtilHelper $utilHelper
35+ * @param Twig_Environment $templating
2936 */
30- public function __construct (UtilHelper $ util )
37+ public function __construct (UtilHelper $ util, Twig_Environment $ templating )
3138 {
3239 $ this ->util = $ util ;
40+ $ this ->templating = $ templating ;
3341 }
3442
3543
@@ -250,14 +258,21 @@ public function jQueryButtonToRemote($name, $url, $options = array(), $htmlOptio
250258 */
251259 public function jQueryFormToRemote ($ form , $ options = array (), $ htmlOptions = array ())
252260 {
261+ if ($ form instanceof FormView) {
262+ $ options ['form ' ] = true ;
263+ $ htmlOptions ['onsubmit ' ] = $ this ->jQueryRemoteFunction ($ form ->vars ['action ' ], $ options ) . '; return false; ' ;
264+
265+ //Après suppression du BC (ci-dessous), la méthode devra être uniquement ce cas
266+ return $ this ->templating ->getRuntime ('Symfony\Bridge\Twig\Form\TwigRenderer ' )
267+ ->renderBlock ($ form , 'form_start ' , ['attr ' => $ htmlOptions ]);
268+ }
269+
253270 //Set Url
254271 if (isset ($ options ['url ' ])) {
255272 $ url = $ options ['url ' ];
256273 unset($ options ['url ' ]);
257274 } else {
258- if ($ form instanceof FormView) {
259- $ url = $ form ->vars ['action ' ];
260- } elseif (is_string ($ form )) {
275+ if (is_string ($ form )) {
261276 // BC
262277 $ url = $ form ;
263278 trigger_error ('Use url in jQueryFormToRemote \'s first argument is deprecated since 2.2 version. ' , E_USER_DEPRECATED );
0 commit comments