SSブログ

[Note] jQuery を困らせる製品 - A certain product against the jQuery [jQuery]

突然ですが、jQuery セレクターといえども、指定されたセレクターを解決できずに、降参することがあるよ、という話です。

I'm sure that there are some cases that the jQuery selector can't work as usual and should throw something exceptions, because jQuery doesn't support some strange usages.

自分が経験したのは、ASP.NET Web フォーム用の、某サードパーティ製コントロール コンポーネントの場合。

I experienced one of the situation when I used the control component product by the certain third party, for the ASP.NET Web Form.

なかなかよさそうなコンポーネントで、次にリリースするシステムに採用しました。

When I saw the demonstration, I felt good about the product, and I decided to adopt the product in my next Web App project.

一応、ユーザー要求として、エラーが発生したコントロールの外観を目立つようにしてほしい、ということで。

On the other hand, the system users required me to change the appearances of the error controls to attract attention.

jQuery を使って、定型的な実装を組み込みました。

Using jQuery, I incorporated typical implementation.

Page_Validators の中で IsValid が false の Validator の controltovalidate の色を変えるってやつです。

The process I implemented looked for the error controls with watching the IsValid property of Validators in Page_Validators, and set the appearance of the element specified by the controltovalidate property of the Validator as the id.

ところが、特定のコントロールでエラーを発生させると、外観変更部の jQuery セレクターが例外をスローするんです。

But, when the particular control's error occurred, the jQuery selector in above process threw the exception.

ちょっと調べてみたら、マークアップで ControlToValidate 属性に設定したコントロールのクライアント ID と、クライアントの controltovalidate プロパティの内容が違っていて。

After some my trace, I found  there was a difference between the "ControlToValidate" attribute in aspx markup for Validator Control and the "controltovalidate" property in the Client Validator Control.

controltovalidate には、たぶん内部の編集用エレメントの id なんでしょうが、知らない文字列が設定されている。

I didn't know the content of the "controltovalidate"; I thought it should be the client id of the something inner editable element among the component control.

その文字列の中に、文字としてコロン(:)があったりして。

And I found some colons (:) as the letter of the client id string.

jQuery セレクターに渡す文字列の中のコロンはフィルターのプレフィックスですから、id 文字列の中にコロンが含まれるのはまずいですよね。

I knew jQuery selector parses colon as the prefix for the filters, so I understood it was bad situation for jQuery.

こういう状態のエレメントを id から抽出しようとすると、jQuery セレクターはお手上げです。

When the jQuery selector was called with such above id, it should throw an exception.

他の文字ならまだしも、よりによってコロンを使わなくてもいいでしょうに。

I accept the secret tricks, but using colon as a letter of the id string of elements is bad.

なお、そういう id を持つエレメントでも、Native JavaScript の getElementById とかだと、ちゃんと取得してくれます。

In addition, the Native JavaScript getElementById method accepts even the elements having such id.

今回のケースでは、空の jQuery セレクターに対して、controltovalidate プロパティで特定されるエレメントを getElementById で取得して追加していくという方法を取りました。

With this case, I took the method that I got the element identified by controltovalidate property with getElementById method and added it into empty jQuery selector.

まあ…サードパーティ製コンポーネントも、いろいろ拡張機能を提供してくれるのはうれしいんですが。

I am glad that the component made in a third party provides various extensions, but ...

ここだけの話、こっそりつまんねー小細工すんなよ ... と思いました。

However, I never want bad secret tricks of their products.


nice!(2)  コメント(2)  トラックバック(0) 

nice! 2

コメント 2

ゆうみ

書こうか書くまいか 悩んでたんですが
最後の下りで 大笑いしました。
by ゆうみ (2014-09-19 22:54) 

One-for-you

トラップ?w
どっちの行を読むか、迷わずNippon語の方を読みましたw
久しぶりです、変わりないですか? レス不にてw
by One-for-you (2014-09-20 02:45) 

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。