teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

追記の暫定的な解決策を編集

2020/03/11 04:40

投稿

tsurugi
tsurugi

スコア89

title CHANGED
File without changes
body CHANGED
@@ -28,19 +28,13 @@
28
28
  ---
29
29
 
30
30
  追記:
31
+ preventService()での止め方はわからなかったものの、表示/非表示だけなら余計なことを考えず属性の操作をするのが手っ取り早かったです。
32
+
31
33
  ```js
34
+ //表示
32
- UIkit.util.on(document, 'show', '.uk-tooltip.uk-active', function(e) {
35
+ password_element.setAttribute('uk-tooltip','title:'+password_incorrect_reason)
33
- if(is_password_correct){
36
+ //非表示
34
- const tooltip_array = document.getElementsByClassName('uk-tooltip')
37
+ password_element.removeAttribute('uk-tooltip')
35
- for(let i=0;i<tooltip_array.length;i++){
36
- if(tooltip_array[i]){
37
- tooltip_array[i].parentNode.removeChild(tooltip_array[i]);
38
- }
39
- }
40
- }
41
- });
42
38
  ```
43
39
 
44
- 現状はこの**表示する前に追加された要素を削除する力技**で対処できています。
45
-
46
- 要件は満たで解決言えば解決んですが、本質的な解決ではないので引き続き回答は募集させていだきます……
40
+ かしpreventService()使い方は依然してわからないので回答は募集たままにします。

2

暫定的な解決方法を追記。

2020/03/11 04:40

投稿

tsurugi
tsurugi

スコア89

title CHANGED
File without changes
body CHANGED
@@ -23,4 +23,24 @@
23
23
 
24
24
  しかし実際は、`Tooltipは非表示`は出力されますが`e.preventDefault();`は書き方を間違えているのかTooltipが表示されてしまいます。
25
25
 
26
- ご教授のほど、よろしくお願いします。
26
+ ご教授のほど、よろしくお願いします。
27
+
28
+ ---
29
+
30
+ 追記:
31
+ ```js
32
+ UIkit.util.on(document, 'show', '.uk-tooltip.uk-active', function(e) {
33
+ if(is_password_correct){
34
+ const tooltip_array = document.getElementsByClassName('uk-tooltip')
35
+ for(let i=0;i<tooltip_array.length;i++){
36
+ if(tooltip_array[i]){
37
+ tooltip_array[i].parentNode.removeChild(tooltip_array[i]);
38
+ }
39
+ }
40
+ }
41
+ });
42
+ ```
43
+
44
+ 現状はこの**表示する前に追加された要素を削除する力技**で対処できています。
45
+
46
+ 要件は満たしたので解決と言えば解決なんですが、本質的な解決ではないので引き続き回答は募集させていただきます……。

1

文章の修正、変数名を意味のあるものにした

2020/03/11 02:52

投稿

tsurugi
tsurugi

スコア89

title CHANGED
File without changes
body CHANGED
@@ -1,14 +1,17 @@
1
1
  UIKitを使ってユーザー登録画面を作成しています。
2
2
 
3
- パスワードのバリデーションについて、必要に応じて`input type="password"`の要素に対してtooltipで警告(そのパスワードが使えない理由)について警告しす。
3
+ パスワードのバリデーションについて、必要に応じて`input type="password"`の要素に対してtooltipで警告(そのパスワードが使えない理由)について警告するUIを作成す。
4
+
4
5
  ```js
5
- UIkit.tooltip(password_element, {title:str})
6
+ UIkit.tooltip(password_element, {title:password_incorrect_reason})
6
7
  ```
7
8
 
8
- これでTooltipが表示されます。
9
+ これで、パスワードが条件を満たしていないときにTooltipが表示されます。
9
10
 
10
- [公式のドキュメント](https://getuikit.com/docs/tooltip)を見る限り以下のコードでTooltipが表示できるよう思います。
11
+ しかしパスワードが条件を満たしている時はTooltipを非表示にする必要があります。
11
12
 
13
+ [公式のドキュメント](https://getuikit.com/docs/tooltip)を見る限り、以下のコードでTooltipを非表示にできるように思います。
14
+
12
15
  ```js
13
16
  UIkit.util.on(document, 'beforehide', '.uk-tooltip.uk-active', function(e) {
14
17
  if(is_password_correct){
@@ -18,6 +21,6 @@
18
21
  });
19
22
  ```
20
23
 
21
- しかし実際は、`Tooltipは非表示`は出力されますが`e.preventDefault();`は書き方を間違えているのかTooltipが表示されてしまいます。
24
+ しかし実際は、`Tooltipは非表示`は出力されますが`e.preventDefault();`は書き方を間違えているのかTooltipが表示されてしまいます。
22
25
 
23
26
  ご教授のほど、よろしくお願いします。