Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
3a93144f
Commit
3a93144f
authored
Oct 20, 2015
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1481 from tastejs/react/controlled-input-component
React: Remove direct DOM manipulation
parents
aff74a63
15db45e6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
examples/react/js/app.jsx
examples/react/js/app.jsx
+10
-4
No files found.
examples/react/js/app.jsx
View file @
3a93144f
...
@@ -20,7 +20,8 @@ var app = app || {};
...
@@ -20,7 +20,8 @@ var app = app || {};
getInitialState
:
function
()
{
getInitialState
:
function
()
{
return
{
return
{
nowShowing
:
app
.
ALL_TODOS
,
nowShowing
:
app
.
ALL_TODOS
,
editing
:
null
editing
:
null
,
newTodo
:
''
};
};
},
},
...
@@ -34,6 +35,10 @@ var app = app || {};
...
@@ -34,6 +35,10 @@ var app = app || {};
router
.
init
(
'
/
'
);
router
.
init
(
'
/
'
);
},
},
handleChange
:
function
(
event
)
{
this
.
setState
({
newTodo
:
event
.
target
.
value
});
},
handleNewTodoKeyDown
:
function
(
event
)
{
handleNewTodoKeyDown
:
function
(
event
)
{
if
(
event
.
keyCode
!==
ENTER_KEY
)
{
if
(
event
.
keyCode
!==
ENTER_KEY
)
{
return
;
return
;
...
@@ -41,11 +46,11 @@ var app = app || {};
...
@@ -41,11 +46,11 @@ var app = app || {};
event
.
preventDefault
();
event
.
preventDefault
();
var
val
=
React
.
findDOMNode
(
this
.
refs
.
newField
).
value
.
trim
();
var
val
=
this
.
state
.
newTodo
.
trim
();
if
(
val
)
{
if
(
val
)
{
this
.
props
.
model
.
addTodo
(
val
);
this
.
props
.
model
.
addTodo
(
val
);
React
.
findDOMNode
(
this
.
refs
.
newField
).
value
=
''
;
this
.
setState
({
newTodo
:
''
})
;
}
}
},
},
...
@@ -147,10 +152,11 @@ var app = app || {};
...
@@ -147,10 +152,11 @@ var app = app || {};
<
header
className=
"header"
>
<
header
className=
"header"
>
<
h1
>
todos
</
h1
>
<
h1
>
todos
</
h1
>
<
input
<
input
ref=
"newField"
className=
"new-todo"
className=
"new-todo"
placeholder=
"What needs to be done?"
placeholder=
"What needs to be done?"
value=
{
this
.
state
.
newTodo
}
onKeyDown=
{
this
.
handleNewTodoKeyDown
}
onKeyDown=
{
this
.
handleNewTodoKeyDown
}
onChange=
{
this
.
handleChange
}
autoFocus=
{
true
}
autoFocus=
{
true
}
/>
/>
</
header
>
</
header
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment