शुरू करने के लिए कूदता है मैं खाली वर्कशीट में भरने के संपादन को सक्षम करने के लिए मॉड्यूल react-simple-contenteditable का उपयोग कर रहा हूं। एक इनपुट तत्व के बजाय मुझे एक सामग्री संपादन योग्य तत्व का उपयोग करना चाहिए क्योंकि मैं समस्या का पाठ लपेटना चाहता हूं। उदाहरण के लिए, यदि किसी समस्या में एक खाली है, तो यह पाठ को रिक्त, रिक्त और बाद के भाग से पहले भाग में तीन खंडों में विभाजित करता है। अगर मैं बाहरी दो को अलग div
एस (या इनपुट फ़ील्ड) के रूप में प्रस्तुत करना था, तो पाठ अनुच्छेद की तरह लपेट नहीं होगा। इसके बजाय, मेरे पास एक ही संतोषजनक div
होना चाहिए जिसमें किसी भी तरफ रिक्त और मुक्त टेक्स्ट के लिए इनपुट फ़ील्ड हो।प्रतिक्रिया संतोषजनक कर्सर
टेक्स्ट लपेट रहा है जैसे मैं चाहता हूं, लेकिन जब मैं संतुष्ट फ़ील्ड में टेक्स्ट टाइप करता हूं, तो कर्सर शुरुआत में कूदता है। मुझे समझ में नहीं आया क्योंकि मैंने module's github site पर उदाहरण का प्रयास क्यों किया और यह पूरी तरह से काम करता है, और हालांकि मेरा कार्यान्वयन थोड़ा अधिक जटिल है, यह अनिवार्य रूप से वही काम करता है। , यहाँ
handleProblemChange(event, problemIdx) {
const problems = cloneDeep(this.state.problems);
event.target.children[0].childNodes.forEach((textPieceNode, idx) => {
if (textPieceNode.constructor === Text) {
problems[problemIdx].textPieces[idx].text = textPieceNode.wholeText;
} else {
problems[problemIdx].textPieces[idx].text = textPieceNode.childNodes[0].value;
}
});
this.setState({ problems });
}
और राज्य इसे करने के लिए संदर्भित करता है बस बात स्पष्ट कर देना:
render() {
const textPieces =
<div className='new-form-text-pieces'>
{
this.props.problem.textPieces.map((textPiece, idx) => {
if (textPiece.blank) {
return (
<div data-blank={true} className='blank' key={ textPiece.id } style={{display: 'inline'}}>
<input
placeholder="Answer blank"
className='new-form-answer-input'
value={ this.props.problem.textPieces[idx].text }
onChange={ (event) => this.props.handleTextPiecesInput(this.props.problemIdx, idx, event.target.value) }
/>
<button className='modify-blank remove-blank' onClick={ (event) => this.props.removeBlank(this.props.problemIdx, idx) }>-</button>
</div>
);
} else {
let text = this.props.problem.textPieces[idx].text;
const placeholder = idx === 0 ? 'Problem text' : '...continue text';
// text = text === '' ? placeholder : text;
if (text === '') {
text = <span style={{color:'gray'}}>{placeholder}</span>;
} else {
}
return (
this.props.isTextSplit ?
<TextPiece
key={ textPiece.id }
problemIdx={this.props.problemIdx}
textPieceIdx={idx}
dropBlank={this.props.dropBlank}
moveBlank={this.props.moveBlank}
>
<div style={{display: 'inline-block', }}>{text}</div>
</TextPiece>
: text
);
}
})
}
</div>;
return (
this.props.isTextSplit ? textPieces :
<ContentEditable
html={ReactDOMServer.renderToStaticMarkup(textPieces)}
className="my-class"
tagName="div"
onChange={ (event, value) => this.props.handleProblemChange(event, this.props.problemIdx, value) }
contentEditable='plaintext-only'
/>
);
}
यहाँ onChange
समारोह है:
यहाँ मेरी समारोह प्रस्तुत करना <ContentEditable />
का उपयोग करता है है
this.state = {
problems: [
{
id: shortid.generate(),
textPieces: [
{
text : "Three days was simply not a(n)",
blank : false,
id: shortid.generate(),
},
{
text : "acceptable",
blank : true,
id: shortid.generate(),
},
{
text : "amount of time to complete such a lot of work.",
blank : false,
id: shortid.generate(),
}
]
}
धन्यवाद बहुत
धन्यवाद करने के लिए सक्षम हो जाएगा! मैं ड्राफ्टजेएस पर एक और नज़र डालेगा, यह बहुत जटिल लग रहा था। क्या इसे केवल सरल क्षेत्रों के लिए कार्यान्वित किया जा सकता है जैसे कि मैं क्या कर रहा हूं या यह सिर्फ समृद्ध टेक्स्ट संपादन के लिए है, जैसे इसका विज्ञापन किया गया है? –
यह दोनों कर सकते हैं। हालांकि सरल नहीं है, मैं कर्सर राज्य को प्रबंधित करने से सरल होने पर शर्त लगाऊंगा। – klugjo
अब इस पर वापस आ रहा है ... मैंने ड्राफ्टजेएस के दस्तावेज़ों के माध्यम से स्कैन किया है और मुझे किसी अन्य प्रश्न का उत्तर नहीं मिल रहा है, इसलिए मैंने सोचा कि शायद आपको पता चलेगा: क्या मैं आंतरिक सामग्री HTML तत्व बना सकता हूं? सामग्री संपादन योग्य पाठ के अलावा, मुझे इसके चारों ओर एक बॉक्स के साथ पाठ की आवश्यकता है। –