Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81165 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule ReactDOMForm
10
*/
11
12
"use strict";
13
14
var EventConstants = require('EventConstants');
15
var LocalEventTrapMixin = require('LocalEventTrapMixin');
16
var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin');
17
var ReactCompositeComponent = require('ReactCompositeComponent');
18
var ReactElement = require('ReactElement');
19
var ReactDOM = require('ReactDOM');
20
21
// Store a reference to the <form> `ReactDOMComponent`. TODO: use string
22
var form = ReactElement.createFactory(ReactDOM.form.type);
23
24
/**
25
* Since onSubmit doesn't bubble OR capture on the top level in IE8, we need
26
* to capture it on the <form> element itself. There are lots of hacks we could
27
* do to accomplish this, but the most reliable is to make <form> a
28
* composite component and use `componentDidMount` to attach the event handlers.
29
*/
30
var ReactDOMForm = ReactCompositeComponent.createClass({
31
displayName: 'ReactDOMForm',
32
33
mixins: [ReactBrowserComponentMixin, LocalEventTrapMixin],
34
35
render: function() {
36
// TODO: Instead of using `ReactDOM` directly, we should use JSX. However,
37
// `jshint` fails to parse JSX so in order for linting to work in the open
38
// source repo, we need to just use `ReactDOM.form`.
39
return form(this.props);
40
},
41
42
componentDidMount: function() {
43
this.trapBubbledEvent(EventConstants.topLevelTypes.topReset, 'reset');
44
this.trapBubbledEvent(EventConstants.topLevelTypes.topSubmit, 'submit');
45
}
46
});
47
48
module.exports = ReactDOMForm;
49
50