After my last post discussing the missing native form reset directive, I was asked what other missing directives there might be. Which is a great question. AngularJS provides so many great directives out of the box, what could it possibly be missing?
Well, lets start with simple user input events. AngularJS 1.1.5 supports the following events as ng-directives:
While that list is pretty extensive there are two glaring omissions, namely blur and focus events. Luckily these can be easily added as you will see below.
Since there is nothing uniquely special about these two events compared to the list above, we can use the AngularJS source code as a template for adding two directives to support these events. The bonus for doing that is extrapolating and slightly modifying the code for our goals is quick and painless. Lesson to be learned: always look to the source for tips and guidance.
First, a note discussing this approach. I have read various development threads discussing how a focus and/or a blur directive should work. The main debate seems to boil down to a disagreement between essentially adverbs. Specifically 'on' and 'while'. The latter assigns a state indicator that can be monitored to determine if an element is currently blurred or focused. The former, which is the approach the following example will use, follows the native browser event listeners for firing when an event occurs.
Got it? Good. Lets jump in then. Click on the input element to give it focus and then click outside of it to blur it.
It works, but how? Focusing on the
Looking at the directive code on the
Again, there is nothing very special about the code in this directive. In fact anything of interest was discussed in the last post (review here if you need to). Basically the directive will evaluate whatever the AngularJS expression is when the event fires.
NOTE: If you want to do something only when an element has focus (or blurred) you would need to use both directives to monitor the element as this example does.
UPDATE (2013-08-13): AngularJS 1.2.0rc1 now includes blur and focus events! Wooohoooo! Check out the follow-up post to see how it compares.
UPDATE (2013-8-26): Part 2 - Supporting the 'while' adverb through a directive.
Well, lets start with simple user input events. AngularJS 1.1.5 supports the following events as ng-directives:
- click
- dblclick
- mousedown
- mouseup
- mouseover
- mouseout * apparently this one is not documented yet
- mousemove
- mouseenter
- mouseleave
- keydown
- keyup
- keypress
While that list is pretty extensive there are two glaring omissions, namely blur and focus events. Luckily these can be easily added as you will see below.
Since there is nothing uniquely special about these two events compared to the list above, we can use the AngularJS source code as a template for adding two directives to support these events. The bonus for doing that is extrapolating and slightly modifying the code for our goals is quick and painless. Lesson to be learned: always look to the source for tips and guidance.
First, a note discussing this approach. I have read various development threads discussing how a focus and/or a blur directive should work. The main debate seems to boil down to a disagreement between essentially adverbs. Specifically 'on' and 'while'. The latter assigns a state indicator that can be monitored to determine if an element is currently blurred or focused. The former, which is the approach the following example will use, follows the native browser event listeners for firing when an event occurs.
Got it? Good. Lets jump in then. Click on the input element to give it focus and then click outside of it to blur it.
It works, but how? Focusing on the
HTML
tab we can see the directives are simply passing an AngularJS expression that sets the scope variable focused
to either true
or false
if the input element is focused or blurred respectively.Looking at the directive code on the
JavaScript
tab, the first thing you will notice is rather than repeating identical code for each directive I use an angular.forEach to loop through both events and dynamically create a directive for each one.Again, there is nothing very special about the code in this directive. In fact anything of interest was discussed in the last post (review here if you need to). Basically the directive will evaluate whatever the AngularJS expression is when the event fires.
NOTE: If you want to do something only when an element has focus (or blurred) you would need to use both directives to monitor the element as this example does.
UPDATE (2013-08-13): AngularJS 1.2.0rc1 now includes blur and focus events! Wooohoooo! Check out the follow-up post to see how it compares.
UPDATE (2013-8-26): Part 2 - Supporting the 'while' adverb through a directive.
I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
ReplyDeleteVery interesting blog.
FocusMe Crack
Diyarbakır
ReplyDeleteKırklareli
Kastamonu
Siirt
Diyarbakır
QG0L5Q
Eskişehir
ReplyDeleteDenizli
Malatya
Diyarbakır
Kocaeli
82LKH
çankırı
ReplyDeleteelazığ
antep
ağrı
van
U8RH7
415FE
ReplyDeleteHakkari Lojistik
Mersin Parça Eşya Taşıma
Şırnak Lojistik
Adıyaman Parça Eşya Taşıma
Muş Parça Eşya Taşıma
F4AE1
ReplyDeleteAmasya Evden Eve Nakliyat
Hakkari Parça Eşya Taşıma
Samsun Lojistik
İzmir Lojistik
Kilis Şehirler Arası Nakliyat
Çanakkale Şehirler Arası Nakliyat
Aksaray Lojistik
Çerkezköy Oto Elektrik
Kilis Lojistik
DCA40
ReplyDeleteÇerkezköy Evden Eve Nakliyat
Bilecik Evden Eve Nakliyat
buy fat burner
Tekirdağ Parke Ustası
testosterone enanthate
order winstrol stanozolol
order sarms
fat burner for sale
buy anapolon oxymetholone
31D27
ReplyDeletemexc
canlı sohbet ücretsiz
4g mobil proxy
binance referans kod
kucoin
kucoin
en iyi kripto grupları telegram
bitrue
probit
C1614
ReplyDeletecointiger
okex
4g proxy
kaldıraç nasıl yapılır
mercatox
binance
sohbet canlı
mexc
mexc
9C629
ReplyDeletebinance referans kimliği nedir
mexc
btcturk
kripto telegram grupları
kredi kartı ile kripto para alma
canlı sohbet ücretsiz
bitmex
mobil 4g proxy
sohbet canlı
18350
ReplyDeletehttps://www.canli.show/
ücretli show
69B89
ReplyDeleteshow
ücretli show
show
görüntülü show
8097C
ReplyDeletegörüntülü şov whatsapp numarası
glassagram
ReplyDeleteallsmo
instagram gizli hesap görme
revelio
bestwhozi
TF3Q
A91670694C
ReplyDeletegörüntülü sex
sohbet hatti
cam show
sanal seks
seks hattı
sex hattı
görüntülü şov
cam şov
sanal sex
Very thouughtful blog
ReplyDeleteF03F0259CD
ReplyDeletecam show
canli cam show
whatsapp görüntülü şov
telegram show
whatsapp görüntülü show güvenilir
skype şov
telegram görüntülü şov
şov
ücretli show
7F8FAFF352
ReplyDeleteyapay kızlık zarı
stag
cam show
görüntülü şov
canli cam show
viagra
ücretli show
kaldırıcı
ücretli şov