Permalink
Browse files

Fixing issues with ajax forms and mootools. post needs to be lowercase.

Implementing serializeForm() in MootoolsEngine.
Updating doc blocks.
  • Loading branch information...
1 parent 2414a43 commit 6f10f5de6df168f666c5b5b553be7f93627139b4 @markstory markstory committed Jul 25, 2009
@@ -243,6 +243,9 @@ function link($title, $url = null, $options = array()) {
* Uses the selected JS engine to create a submit input
* element that is enhanced with Javascript. Options can include
* both those for FormHelper::submit() and JsBaseEngine::request(), JsBaseEngine::event();
+ *
+ * Forms submitting with this method, cannot send files. Files do not transfer over XmlHttpRequest
+ * and require an iframe.
*
* @param string $title The display text of the submit button.
* @param array $options Array of options to use.
@@ -269,7 +272,7 @@ function submit($caption = null, $options = array()) {
unset($options['url']);
}
if (!isset($options['method'])) {
- $options['method'] = 'POST';
+ $options['method'] = 'post';
}
$options['dataExpression'] = true;
$requestString .= $this->request($url, $options);
@@ -718,15 +721,15 @@ function request($url, $options = array()) {
*
* ### Options
*
- * - handle - selector to the handle element.
- * - snapGrid - The pixel grid that movement snaps to, an array(x, y)
- * - container - The element that acts as a bounding box for the draggable element.
+ * - `handle` - selector to the handle element.
+ * - `snapGrid` - The pixel grid that movement snaps to, an array(x, y)
+ * - `container` - The element that acts as a bounding box for the draggable element.
*
* ### Event Options
*
- * - start - Event fired when the drag starts
- * - drag - Event fired on every step of the drag
- * - stop - Event fired when dragging stops (mouse release)
+ * - `start` - Event fired when the drag starts
+ * - `drag` - Event fired on every step of the drag
+ * - `stop` - Event fired when dragging stops (mouse release)
*
* @param array $options Options array see above.
* @return string Completed drag script
@@ -740,14 +743,14 @@ function drag($options = array()) {
*
* ### Options
*
- * - accept - Selector for elements this droppable will accept.
- * - hoverclass - Class to add to droppable when a draggable is over.
+ * - `accept` - Selector for elements this droppable will accept.
+ * - `hoverclass` - Class to add to droppable when a draggable is over.
*
* ### Event Options
*
- * - drop - Event fired when an element is dropped into the drop zone.
- * - hover - Event fired when a drag enters a drop zone.
- * - leave - Event fired when a drag is removed from a drop zone without being dropped.
+ * - `drop` - Event fired when an element is dropped into the drop zone.
+ * - `hover` - Event fired when a drag enters a drop zone.
+ * - `leave` - Event fired when a drag is removed from a drop zone without being dropped.
*
* @return string Completed drop script
**/
@@ -759,17 +762,17 @@ function drop($options = array()) {
*
* ### Options
*
- * - containment - Container for move action
- * - handle - Selector to handle element. Only this element will start sort action.
- * - revert - Whether or not to use an effect to move sortable into final position.
- * - opacity - Opacity of the placeholder
- * - distance - Distance a sortable must be dragged before sorting starts.
+ * - `containment` - Container for move action
+ * - `handle` - Selector to handle element. Only this element will start sort action.
+ * - `revert` - Whether or not to use an effect to move sortable into final position.
+ * - `opacity` - Opacity of the placeholder
+ * - `distance` - Distance a sortable must be dragged before sorting starts.
*
* ### Event Options
*
- * - start - Event fired when sorting starts
- * - sort - Event fired during sorting
- * - complete - Event fired when sorting completes.
+ * - `start` - Event fired when sorting starts
+ * - `sort` - Event fired during sorting
+ * - `complete` - Event fired when sorting completes.
*
*
* @param array $options Array of options for the sortable. See above.
@@ -783,17 +786,17 @@ function sortable() {
*
* ### Options
*
- * - handle - The id of the element used in sliding.
- * - direction - The direction of the slider either 'vertical' or 'horizontal'
- * - min - The min value for the slider.
- * - max - The max value for the slider.
- * - step - The number of steps or ticks the slider will have.
- * - value - The initial offset of the slider.
+ * - `handle` - The id of the element used in sliding.
+ * - `direction` - The direction of the slider either 'vertical' or 'horizontal'
+ * - `min` - The min value for the slider.
+ * - `max` - The max value for the slider.
+ * - `step` - The number of steps or ticks the slider will have.
+ * - `value` - The initial offset of the slider.
*
* ### Events
*
- * - change - Fired when the slider's value is updated
- * - complete - Fired when the user stops sliding the handle
+ * - `change` - Fired when the slider's value is updated
+ * - `complete` - Fired when the user stops sliding the handle
*
* @return string Completed slider script
**/
@@ -808,8 +811,8 @@ function slider() {
*
* ### Options
*
- * - isForm - is the current selection a form, or an input? (defaults to false)
- * - inline - is the rendered statement going to be used inside another JS statement? (defaults to false)
+ * - `isForm` - is the current selection a form, or an input? (defaults to false)
+ * - `inline` - is the rendered statement going to be used inside another JS statement? (defaults to false)
*
* @param array $options options for serialization generation.
* @return string completed form serialization script
@@ -184,25 +184,28 @@ function request($url, $options = array()) {
$url = $this->url($url);
$options = $this->_mapOptions('request', $options);
$type = $data = null;
- if (isset($options['type']) && strtolower($options['type']) == 'json') {
- $type = '.JSON';
- if (!empty($options['data'])) {
- $data = $this->object($options['data']);
- unset($options['data']);
+ if (isset($options['type']) || isset($options['update'])) {
+ if (isset($options['type']) && strtolower($options['type']) == 'json') {
+ $type = '.JSON';
}
- unset($options['type']);
- }
- if (isset($options['update'])) {
- $options['update'] = str_replace('#', '', $options['update']);
- $type = '.HTML';
- if (!empty($options['data'])) {
- $data = $this->_toQuerystring($options['data']);
- unset($options['data']);
+ if (isset($options['update'])) {
+ $options['update'] = str_replace('#', '', $options['update']);
+ $type = '.HTML';
}
unset($options['type']);
}
+ if (!empty($options['data'])) {
+ $data = $options['data'];
+ unset($options['data']);
+ }
$options['url'] = $url;
$callbacks = array('onComplete', 'onFailure', 'onRequest', 'onSuccess', 'onCancel', 'onException');
+ if (isset($options['dataExpression'])) {
+ $callbacks[] = 'data';
+ unset($options['dataExpression']);
+ } elseif (!empty($data)) {
+ $data = $this->object($data);
+ }
$options = $this->_parseOptions($options, $callbacks);
return "var jsRequest = new Request$type({{$options}}).send($data);";
}
@@ -303,5 +306,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 = '.toQueryString()';
+ if (!$options['inline']) {
+ $method .= ';';
+ }
+ return $selection . $method;
+ }
}
?>
@@ -357,7 +357,7 @@ function testSubmitWithMock() {
$params = array(
'update' => $options['update'], 'data' => 'serialize-code',
- 'method' => 'POST', 'dataExpression' => true
+ 'method' => 'post', 'dataExpression' => true
);
$this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array(
'event', array('click', "ajax-code", $params)
@@ -378,15 +378,15 @@ function testSubmitWithMock() {
'/custom/url', array(
'update' => '#content',
'data' => 'serialize-code',
- 'method' => 'POST',
+ 'method' => 'post',
'dataExpression' => true
)
);
$this->Js->TestJsEngine->expectAt(6, 'dispatchMethod', array('request', $requestParams));
$params = array(
'update' => '#content', 'data' => 'serialize-code',
- 'method' => 'POST', 'dataExpression' => true
+ 'method' => 'post', 'dataExpression' => true
);
$this->Js->TestJsEngine->expectAt(7, 'dispatchMethod', array(
'event', array('click', "ajax-code", $params)
@@ -278,5 +278,28 @@ function testSlider() {
$expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:onChange, onComplete:onComplete, range:[10,40]});';
$this->assertEqual($result, $expected);
}
+/**
+ * test the serializeForm implementation.
+ *
+ * @return void
+ **/
+ function testSerializeForm() {
+ $this->Moo->get('#element');
+ $result = $this->Moo->serializeForm(array('isForm' => true));
+ $expected = '$("element").toQueryString();';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->serializeForm(array('isForm' => true, 'inline' => true));
+ $expected = '$("element").toQueryString()';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->serializeForm(array('isForm' => false));
+ $expected = '$($("element").form).toQueryString();';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->serializeForm(array('isForm' => false, 'inline' => true));
+ $expected = '$($("element").form).toQueryString()';
+ $this->assertEqual($result, $expected);
+ }
}
?>

0 comments on commit 6f10f5d

Please sign in to comment.