Browse files

implementing serializeForm() in Prototype engine.

  • Loading branch information...
1 parent def4c98 commit dda6c93529dd9085d0867448be1456fb350326d8 @markstory markstory committed Jul 25, 2009
View
19 cake/libs/view/helpers/prototype_engine.php
@@ -281,5 +281,24 @@ function slider($options = array()) {
$this->selection = $slider;
return $out;
}
+/**
+ * Serialize the form attached to $selector.
+ *
+ * @param array $options Array of options.
+ * @return string Completed serializeForm() snippet
+ * @see JsHelper::serializeForm()
+ **/
+ function serializeForm($options = array()) {
+ $options = array_merge(array('isForm' => false, 'inline' => false), $options);
+ $selection = $this->selection;
+ if (!$options['isForm']) {
+ $selection = '$(' . $this->selection . '.form)';
+ }
+ $method = '.serialize()';
+ if (!$options['inline']) {
+ $method .= ';';
+ }
+ return $selection . $method;
+ }
}
?>
View
25 cake/tests/cases/libs/view/helpers/prototype_engine.test.php
@@ -2,8 +2,6 @@
/**
* PrototypeEngine TestCase
*
- *
- *
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
@@ -272,5 +270,28 @@ function testSlider() {
$expected = 'var jsSlider = new Control.Slider($("handle"), $("element"), {axis:"horizontal", onChange:onComplete, onSlide:onChange, sliderValue:4});';
$this->assertEqual($result, $expected);
}
+/**
+ * test the serializeForm implementation.
+ *
+ * @return void
+ **/
+ function testSerializeForm() {
+ $this->Proto->get('#element');
+ $result = $this->Proto->serializeForm(array('isForm' => true));
+ $expected = '$("element").serialize();';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->serializeForm(array('isForm' => true, 'inline' => true));
+ $expected = '$("element").serialize()';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->serializeForm(array('isForm' => false));
+ $expected = '$($("element").form).serialize();';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->serializeForm(array('isForm' => false, 'inline' => true));
+ $expected = '$($("element").form).serialize()';
+ $this->assertEqual($result, $expected);
+ }
}
?>

0 comments on commit dda6c93

Please sign in to comment.