开发者

Referencing the selected text in a textarea

开发者 https://www.devze.com 2023-02-08 02:18 出处:网络
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.

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.' ].
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号