prevent copy+paste for TextArea() - actionscript-3

How to prevent ctrl+v paste for flash.display.textarea()?
field.selectable = false; does not seem to work, also it disables caret/cursor

this seem to work in TextEvent listener, any comments is it too bad solution to avoid copy+paste to a field ?
if (evt.text.length >1)
evt.preventDefault () ;

A TextArea is an editable textfield. You should use another component if you want to prevent copy / paste.

The TextArea component has a textField property. Setting the mouseEnabled property of the textField should have the desired effect.
var ta:TextArea = new TextArea();
ta.textField.mouseEnabled = false;
This disables the caret cursor and prevents selection of the text.

If you can, use a different component instead of TextArea, as monkee suggested.
If you're really into protecting against copying your text data you might even want to consider drawing the text on a canvas directly so it's really impossible to grab it unless the user does OCR or something.

We have another solution for it
field.mouseChildren = false;
so it will not allow to copy the data

Related

Set paper-button text dynamically in polymer 1.0

Trying to add the submit button dynamically through javascript, below is the code snippet, not sure which attribute to use for setting the text.
var dynSubmit = document.createElement("paper-button");
dynSubmit.setAttribute("on-click", "submitForm");
//dynSubmit.setAttribute("Value", "Submit");
parent.$.iron-form.appendChild(dynSubmit);
The commented code does not work, How do i set the caption of submit button?
You can set the button's innerHTML.
Polymer.dom(dynSubmit).innerHTML = "Submit";
Thanks to #jonsS0 for his handy comment.
Avoid using innerHTML with Polymer, or at all really; it's slow, it's where XSS can get in, and you shouldn't need it.
Instead use textContent:
dynSubmit.textContent = 'Submit';
You can set this without breaking the ripple and you shouldn't need the Polymer.dom(dynSubmit) as it's an exposed property on the underlying element.

Want `­` to be always visible

I'm working on a web app and users sometimes paste in things they've copy/pasted from other places and that input may come with the ­ character (0xAD). I don't want to filter it out, I simply need the user to see that there is an invisible character there, so they have no surprises later.
Does anyone know a way to make the ­ always be visible? To show a hyphen, rather than remain hidden? I suspect a custom web font might be needed, if so, does anyone know of a pre-existing one?
You would need to either use JavaScript or a custom typeface that has a visible glyph for the soft-hyphen character. Given the impracticalities of working with typefaces for the web (and burdening the user with an additional hundred-kilobyte download) I think the JavaScript approach is best, like so:
document.addEventListener("DOMContentLoaded", function(domReadyEvent) {
var textBoxes = document.querySelectorAll("input[type=text]");
for(var i=0;i<textBoxes.length;i++) {
textBoxes[i].addEventListener("paste", function(pasteEvent) {
var textBox = pasteEvent.target;
textBox.value = textBox.value.replace( "\xAD", "-" );
} );
}
} );

ColorPicker not editable in Form -> FormItem

Please note the remark mentioned WORKAROUND at the end of this question.
Based on a Dictionary based specification, one of my classes creates a Form programmatically.
Adding TextInput or DatePicker to FormItemss works as expected.
Unfortunately, the following code just creates a colored rectangle, not the actual picker:
ti = new ColorPicker();
ColorPicker( ti ).selectedColor = TAColor( _spec[ key ].value ).color;
and later on
formItem.addElement( ti );
The Form is embedded in a TitleWindow component presented using
PopUpManager.addPopUp(...);
When added to TitleWindow, it shows up correctly, within Form->FormItem not:
I can't image, why the picker doesn't appear. Do you?
WORKAROUND:
If I wrap the ColorPicker inside a Group things work:
ti = new Group();
Group( ti ).addElement( new ColorPicker() );
In this case, the ColorPicker appears as editable.
Still, I'd be too happy to learn what the problem with my initial solution. Bug?
A DateField (which extends ComboBase like ColorPicker) behaves properly in a spark Form. But in the ColorPicker, the mouse down handler of the button never gets called. I think that maybe the skin part that handles the mouse clicks (it must be a button) is not properly dimensionned, and the result is it is not shown. I've come to this conclusion because within an mx Form, the ColorPicker doesn't display as it does when it is added to the regular displaylist...
Hope this helps...
In the code you've provided, you never add the colorPicker as a child to any parent container; as such it will never show up anywhere.
You probably need to do something like:
formItem.addChild(ti );
[or for a Spark formItem]:
formItem.addElement(ti );
I'm confused as to why you're seeing a rectangle.

Giving/obtaining a reference to (or the name of) a UIScrollBar in a TextArea

This is such a mindnumbingly simple question, but apparently all the forums where actionscript is discussed (or at least all the ones on google) aren't very well managed.
I have a textArea. It has a UIScrollbar. I want to be able to reference that scrollbar. I heard there's an update() function, and that may be able to save me from the inexplicable things this damnable UIScrollbar is doing on its own.
(btw, actionscript = joke language)
When scrollbar is added to TextArea, it dispatches event ADDED. You can catch its scrollbar like this:
textArea.addEventListener(Event.ADDED, onTextAreaChildAdded);
private function onTextAreaChildAdded(event:Event):void {
if (event.target is UIScrollBar) {
//you got it
var scrollBar:UIScrollBar = event.target as UIScrollBar;
}
}
Event with scrollbar will be fired once. There is also many other stuff that adds into TextArea, so type check is needed.
Know ya jokes and be cool ^_^
Edit: wrong... Real solution seems to be just textArea.verticalScrollBar.
In your class just write:
private var usb:UIScrollBar = new UIScrollBar();
and voilá, usb is your reference.

Using visibility: hidden and display: none together in CSS?

The reason I want to use the together is that I want to hide the content like display: none does, without leaving any whitespace as visibility: hidden does.
At the same time I want the hidden content not to be copied when the user copies the entire table from the webpage, not because it is sensitive information but because the user hid the field and therefore doesn't want it copied. visibility: hidden doesn't copy but display: none does, so I have quite a dilemma.
Anyone know a solution?
Edit:
What I ended up doing was just what was suggested, save the information as Javascript (as it is not sensitive information anyways) and create/remove dynamically with Javascript.
I do not think giving the element visibility: hidden prevents the user copying the information in the table, although this may be browser specific behavior. Have a look at the test I've set up: http://jsfiddle.net/a9JhV/
The results from Firefox 3.6.8 on Windows 7 is
Copy ME! Don't copy me :( Copy ME! Copy ME!
Copy ME! Don't copy me :( Copy ME! Copy ME!
Which doesn't work as expected.
I've cooked up some code, it took the quite a bit work of cook up... have a look here: http://jsfiddle.net/a9JhV/7/
It uses jQuery to hide and show the table columns - actually removes them from the DOM, not just play around with their visibility and whatnot. Whee!
Why not remove the node from the page? You could accomplish this by using:
<script type = 'text/javascript' language = 'JavaScript'>
document.getElementById('yourDivId').innerHTML = '';
//OR
document.removeChild(getElementById('yourDivId')); //(I think this is right...document might need to be replaced by the div's parent)
</script>
You should remove the "hidden" DOM object using javascript and then recreate it again if user wants it back. Data from deleted records can be stored in session storage or hidden inputs for example.
If you want elements HIDDEN from the source, place them in a separate text file and load it using an ajax-like call... this will prevent the html from being in the source.
If you place a clear image OVER the content they also will not be able to highlight it easily (and by using javascript you can likely disable their ability to do a ctrl+a)
hope that helps!
It's a good idea to create an object to represent the table:
var myTable = function(tableName){
// If you want to assign columns dynamically you could create this.addColumn();
this.Columns = new Array(
new Array("row1","row2","row3","row4"),
new Array("row1","row2","row3","row4")
);
this.reBuild = function(){
for (col in this.Columns){
for(row in this.Columns[col]){
// put the cell in the table
}
}
};
};
I didn't test this code, it should just illustrate the gist of storing and building a table.