Development

#2058 ([PATCH] sfFormValidationPlugin conflicts with object_admin_double_list helper)

You must first sign up to be able to contribute.

Ticket #2058 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] sfFormValidationPlugin conflicts with object_admin_double_list helper

Reported by: Serg.Sokolenko Assigned to: DrCore
Priority: minor Milestone:
Component: plugins Version: 1.0.7
Keywords: sfFormValidationPlugin object_admin_double_list Cc:
Qualification: Unreviewed

Description

As you know sfFormValidationPlugin overrides onsubmit form option for client side validation:

onsubmit="return validate(this)"

but admin generator uses onsubmit option to send double list options:

'onsubmit'  => 'double_list_submit(); return true;'

so, double list options are lost when submiting form.

sfFormValidationPlugin must parse onsubmit option to replace "return true/false" or something else, but not override it.

Change History

09/08/07 14:55:05 changed by DrCore

  • keywords changed from sfFormValidationPlugin object_admin_double_list to admin generator sfFormValidationPlugin object_admin_double_list.
  • component changed from plugins to generator.

Confirmed. Propose to change the onsubmit hijack from de admin generator admin double list to call. The hijack could possible also break other enhancements to the admin generator. Reassigned to component generator.

09/09/07 01:57:55 changed by DrCore

  • component changed from generator to helpers.
  • qualification set to Unreviewed.

09/09/07 14:48:13 changed by DrCore

  • keywords changed from admin generator sfFormValidationPlugin object_admin_double_list to sfFormValidationPlugin object_admin_double_list.
  • owner changed from fabien to DrCore.
  • status changed from new to assigned.
  • component changed from helpers to plugins.
  • summary changed from sfFormValidationPlugin conflicts with object_admin_double_list helper to [PATCH] sfFormValidationPlugin conflicts with object_admin_double_list helper.

After further invesigations, the problem is related to the sfFormValidation plugin (not within Symfony). sfFormValidation does not take into account an existing onsubmit tag but creates a new tag. The patch uses a regex to scan for an existing "return true;" element if the onsubmit tag exists and adds a "validate(this)" direction to the return.

Index: sfFormValidationPlugin/lib/helper/FormHelper.php
===================================================================
--- sfFormValidationPlugin/lib/helper/FormHelper.php    (revision 28)
+++ sfFormValidationPlugin/lib/helper/FormHelper.php    (working copy)
@@ -140,10 +140,19 @@
     $html_options['enctype'] = 'multipart/form-data';
   }
 
+  // Parse previous onsubmit string and add validat(this) to return
+  if ($onsubmit = _get_option($html_options, 'onsubmit'))
+  {
+    $html_options['onsubmit'] =  preg_replace('/(.*return )true[;]*/i', '\\1 validate(this);', $onsubmit);
+  }
+  else
+  {
+    $html_options['onsubmit'] = 'return validate(this)';
+  }
+
   $html_options['action'] = url_for($url_for_options);
 
   // Added for client side form validation (AN)
-  $html_options['onsubmit'] = 'return validate(this)';
   $lastForm = LastForm::singleton();
   $lastForm->setRoute($url_for_options, $html_options['method']);
   // End client side form validation (AN)

This patch will not offer an solution for cases where already a custom 'return' command has been setup. It is recommended in those situations to revise the developed code to manually include the "validate(this)" command.

09/11/07 10:07:08 changed by Alon.Noy

  • status changed from assigned to closed.
  • version changed from 1.0.5 to 1.0.7.
  • resolution set to fixed.

v1.1.2 released with bugfix

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.