Kod Panosu

Kopyala, Yapıştır, Hatırla, Kodla..

Placeholder Yazılabilen, Şifreler İçin De Kullanılabilen, TabIndex Alabilen TextInput

Orijinal CaptionTextInput Class’ı için bkz. Spark TextInput with Caption (Watermark)

package components
{
	import flash.events.FocusEvent;

	import mx.core.UIComponent;

	import spark.components.TextInput;

	import spark.skins.mobile.TextInputSkin;

	public class CaptionTextInput extends TextInput
	{
		private var _displayAsPassword:Boolean;
		private var _showsCaption:Boolean;
		private var _caption:String;

		public function CaptionTextInput()
		{
			super();
			//	bunu yapmazsak tabIndex calismaz
			this.setStyle("skinClass", Class(spark.skins.mobile.TextInputSkin));
			this.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
			this.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
		}

		[Bindable("change")]
		[Bindable("textChanged")]
		override public function set text(value:String):void {
			this._showsCaption = false;
			super.displayAsPassword = _displayAsPassword;
			super.text = value;
		}

		override public function set displayAsPassword(value:Boolean):void{
			if(!this._showsCaption){
				super.displayAsPassword = value;
			}
			_displayAsPassword = value;
		}

		override public function get text():String {
			if (this._showsCaption) {
				return "";
			}
			else return super.text;
		}

		/**
		 * The value to be shown if the textfield has no text (this.text == '')
		 */
		public function set caption(value:String):void {
			if (super.text == "") {
				super.displayAsPassword = false;
				super.text = value;
				this._caption = value;
				this._showsCaption = true;
			}
		}

		private function onFocusIn(ev:FocusEvent):void {
			if (this._showsCaption) {
				this._showsCaption = false;
				super.displayAsPassword = _displayAsPassword;
				super.text = "";
			}
		}

		private function onFocusOut(ev:FocusEvent):void {
			if (this.text == "") {
				this._showsCaption = true;
				super.displayAsPassword = false;
				super.text = _caption;
			}
		}
	}
}

Yorum bırakın