Skip to content

Commit 6d63d61

Browse files
author
jacobawenger
committed
No longer allow empty strings to be submitted to Firebase.
1 parent 6df0136 commit 6d63d61

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

examples/todoApp/js/todoAppFirebaseExplicit.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ var TodoApp2 = React.createClass({
3434

3535
handleSubmit: function(e) {
3636
e.preventDefault();
37-
this.firebaseRef.push({
38-
text: this.state.text
39-
});
40-
this.setState({text: ""});
37+
if (this.state.text) {
38+
this.firebaseRef.push({
39+
text: this.state.text
40+
});
41+
this.setState({text: ""});
42+
}
4143
},
4244

4345
render: function() {

examples/todoApp/js/todoAppFirebaseImplicit.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ var TodoApp3 = React.createClass({
2525

2626
handleSubmit: function(e) {
2727
e.preventDefault();
28-
this.firebaseRefs["items"].push({
29-
text: this.state.text
30-
});
31-
this.setState({text: ""});
28+
if (this.state.text) {
29+
this.firebaseRefs["items"].push({
30+
text: this.state.text
31+
});
32+
this.setState({text: ""});
33+
}
3234
},
3335

3436
render: function() {

examples/todoApp/js/todoAppOriginal.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ var TodoApp1 = React.createClass({
1919

2020
handleSubmit: function(e) {
2121
e.preventDefault();
22-
var nextItems = this.state.items.concat([{
23-
text: this.state.text
24-
}]);
25-
this.setState({
26-
items: nextItems,
27-
text: ""
28-
});
22+
if (this.state.text) {
23+
var nextItems = this.state.items.concat([{
24+
text: this.state.text
25+
}]);
26+
this.setState({
27+
items: nextItems,
28+
text: ""
29+
});
30+
}
2931
},
3032

3133
render: function() {

0 commit comments

Comments
 (0)