I want to add a "copy to clipboard" button that copies only the checked checkboxes. with line break between contents. This is what i have so far (copies everything and without line break). please help.
The Button:
<a:commandButton
id="copyURLsToClipboard" value="Copy to Clipboard"
style="width: 120px;"
onclick="onCopyClipboardClicked('#{urlAction.escapeJavaScript()}'); simulateClick(this); return false;"
onfocus="highlightButton(this);"
onblur="unhighlightButton(this);" />
The JS function:
function onCopyClipboardClicked(text) {
if (window.clipboardData && clipboardData.setData) {
clipboardData.setData("Text", text);
} else {
alert("Clipboard not found");
}
}
The checkboxes:
<div id="urlsContainer" class="list-group"
style='width: 350px; word-wrap: break-word;margin-top: 10px'>
<a:repeat value="#{urlAction.urlsIndexList}" var="_urlIndex">
<a href='#' class='list-group-item'
style='float: left; width: 350px; height: 50px;'>
<input
type='checkbox' class="urlCheckBox" name='checkbox-1'
style='margin-left: 15px; float: left;'><span
style='margin-left: 10px; font-size: 12px; float: left; word-break: break-all; width: 300px;'
onclick='showFraim("#{_urlIndex}")'>#{urlAction.getUrl(_urlIndex)}</span>
</input>
</a>
</a:repeat>
</div>
I have all the URLs in the list named "urls" in a java class named urlAction. this is the java function escapeJavaScript():
public List<String> escapeJavaScript() {
if (urls == null ) return null;
List <String> stringUrls = new ArrayList<>();
for ( AggregateUrl au : urls) {
stringUrls.add(escapeJavaScript(au.getUrl()));
}
return stringUrls;
}
Example:
[x] www.google.com
[ ] www.yahoo.com
[x] www.nytimes.com
If I checked the first and third what would be copied to clipboard is this:
www.google.com
www.nytimes.com
Aucun commentaire:
Enregistrer un commentaire