Skip to content

Commit

Permalink
調整表單 input change 事件處理器
Browse files Browse the repository at this point in the history
  • Loading branch information
ginger-lemon committed Oct 26, 2023
1 parent 7ab1525 commit 1c9bb11
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/pages/Edit/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,20 @@ const Edit = () => {
}

// 資料事件處理器
const handleChangeTitle = (e) => {
setNote({ ...note, title: e.target.value })
const handleSetNote = (e) => {
setNote((prev) => ({ ...prev, [e.target.name]: e.target.value}))
}
// const handleChangeTitle = (e) => {
// setNote({ ...note, title: e.target.value })
// }

const handleChangeAuthor = (e) => {
setNote({ ...note, author: e.target.value })
}
// const handleChangeAuthor = (e) => {
// setNote({ ...note, author: e.target.value })
// }

const handleChangeTexts = (e) => {
setNote({ ...note, texts: e.target.value})
}
// const handleChangeTexts = (e) => {
// setNote({ ...note, texts: e.target.value})
// }

const handleChangePassword = (e) => {
// ^字串開頭|[]允許的字元集合規則|+複數字元|$字串結尾
Expand All @@ -185,29 +188,32 @@ const Edit = () => {
<div className={Styles.inputsWrapper}>
<textarea
className={`${Styles.textarea} ${Styles.title}`}
name="title"
type="textarea"
placeholder="Title"
rows={1}
ref={titleRef}
value={note.title}
onChange={handleChangeTitle}
onChange={handleSetNote}
>
</textarea>
<input
type="text"
className={`&{Styles.input} ${Styles.author}`}
name="author"
placeholder="Author"
value={note.author}
onChange={handleChangeAuthor}
onChange={handleSetNote}
>
</input>
<textarea
className={`${Styles.textarea} ${Styles.texts}`}
name="texts"
placeholder="Contents, can write easy markdown type."
ref={textsRef}
rows={15}
value={note.texts}
onChange={handleChangeTexts}
onChange={handleSetNote}
>
</textarea>
<div className={Styles.passwordWrapper}>
Expand All @@ -217,6 +223,7 @@ const Edit = () => {
</label>
<input
className={Styles.password}
name="password"
type={showPassword ? "text" : "password"}
placeholder="6-12 characters"
mimLength={6}
Expand Down

0 comments on commit 1c9bb11

Please sign in to comment.