Datepicker in a User Custom field

Is it possible to add a class to a custom user field to use a datepicker.

Thanks

Edit - The Final Solution:

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">


<script type="text/discourse-plugin" version="0.8">
$( document ).ajaxComplete(function() {
    api.onPageChange((url) =>{
        if (url.match(/\/preferences\/profile/)) {
        	$( function() {
        		var control = $("label:contains('Quit Smoking Date')").next('div.controls');
        		$(control).find('input').addClass('quitDate');
        		$( ".quitDate" ).datepicker();
        	});
	 }
    });
});
</script>

「いいね!」 5

It should already work with this class : div.public-user-field.nameofthefield

For example a custom field Book : div.public-user-field.book

「いいね!」 1

And if it is “Quit Smoking Date”? What then?

I got what I wanted to work using this:

A jQuery date picker in the user field input.

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">


<script type="text/discourse-plugin" version="0.8">
$( document ).ajaxComplete(function() {
    api.onPageChange(() =>{
	$( function() {
		var control = $("label:contains('Quit Smoking Date')").next('div.controls');
		$(control).find('input').addClass('quitDate');
		$( ".quitDate" ).datepicker();
	});
    });
});
</script>

It would be nice to be able to detect the profile page URL using this but I couldn’t get it to work

api.onPageChange((url) => {
        if (url === '/' || url === '/latest' || url === '/top') {

quit-date-calendar

「いいね!」 2

Hey @Vaping_Community :slightly_smiling_face: Glad to see you figured out a solution!

For detecting the profile preferences page, this should work:

<script type="text/discourse-plugin" version="0.8">
    api.onPageChange((url) =>{
        if (url.match(/\/preferences\/profile/)) {
        	$(function() {
        		var control = $("label:contains('Quit Smoking Date')").next('div.controls');
        		$(control).find('input').addClass('quitDate');
        		$(".quitDate").datepicker();
        	});
        }
    });
</script>
「いいね!」 6

I will give this a try today, thank you very much :+1:

「いいね!」 2

Works Perfect, good job! :smile:

「いいね!」 1

これを機能させるためにインストールする必要があるプラグインはありますか?テーマの <head> に追加しましたが、機能していないようです。

プロフィールページの最新コードは以下のとおりです。

<script type="text/discourse-plugin" version="1.4.0">
    api.onPageChange((url) =>{
        if (url.match(/\/preferences\/profile/)) {
            var userField = document.querySelector('.user-field-test-selector');
            
            if (userField) {
                var input = userField.querySelector('input');
                if (input) {
                    input.classList.add('testSelector');
                    input.type = 'date'; // ネイティブHTML5のdate入力を使用
                }
            }
        }
    });
</script>

user-field-test-selector を対応するクラス名に置き換えてください。


input.classList.add('testSelector'); はオプションであり、さらに変更が必要な場合にのみ追加してください。

アカウント作成モーダル用に別のスクリプトを作成する必要があります。

「いいね!」 1

これを年に限定することは可能でしょうか?多様性の監視と管理のためにユーザーのおおよその年齢を知りたいのですが、完全な生年月日を保持したくありません。

また、検索可能なドロップダウンフィールド(つまり、数百のオプションがある場合)にこの種の方法を使用することは可能ですか?

「いいね!」 1

ターゲットとしているフィールドにクラスを追加する方法について、何かアイデアはありますか?それが無理な場合、QueryySelectorクラスをdiv idに置き換えることは可能ですか?