Is there a w开发者_StackOverflow中文版ay to retrieve the text that's currently selected in a text area in Seaside?
You can do it with jQuery/Javascript. When do you want to retrieve the selected text ? What will trigger the retrieval (a user click ? Regular polling ?)
Sorry, pasted it in the wrong place, here's the solution:
MyComponent >> script
^ 'function selectedText(input){
var startPos = input.selectionStart;
var endPos = input.selectionEnd;
var doc = document.selection;
if(doc && doc.createRange().text.length != 0){
document.getElementById(''selectedText'').value = (doc.createRange().text);
} else if (!doc && input.value.substring(startPos,endPos).length != 0){
document.getElementById(''selectedText'').value = (input.value.substring(startPos,endPos))
}
}'
MyComponent >> renderContentOn: html
(html form)
with: [
(html hiddenInput)
id: 'selectedText';
callback: [ :value | selection := value ].
(html textArea)
callback: [ :value | theTextAreaText := value];
id: 'myTextArea'
with: theTextAreaText.
(html submitButton)
onClick: 'selectedText(myTextArea); submitForm(this)';
with: 'Work your magic, J.S.' ].
精彩评论