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>
Steven
22.Март.2018 13:26:52
2
It should already work with this class : div.public-user-field.nameofthefield
For example a custom field Book : div.public-user-field.book
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') {
tshenry
(Taylor)
22.Март.2018 20:05:13
5
Hey @Vaping_Community 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>
I will give this a try today, thank you very much
cokestroke
(Clement Oke)
18.Август.2023 17:25:48
9
Нужно ли мне установить какой-либо плагин, чтобы это заработало? Я добавил его в секцию head своей темы, но, похоже, это не работает.
Canapin
(Coin-coin le Canapin)
21.Август.2023 12:43:47
10
Актуальный код для страницы профиля выглядит так:
<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 input для даты
}
}
}
});
</script>
Замените user-field-test-selector на соответствующий класс:
Строка
input.classList.add('testSelector'); является опциональной и должна быть добавлена только в том случае, если она вам нужна для дальнейших модификаций, как я понимаю.
Для модального окна создания учётной записи следует создать отдельный скрипт.
nathank
(Nathan Kershaw)
29.Август.2023 23:04:11
11
Может ли это ограничение касаться только года? Мы очень заинтересованы в получении приблизительного возраста наших пользователей для мониторинга и управления разнообразием, но не хотим хранить их полную дату рождения.
Также возможно ли использовать подобный метод для создания выпадающего списка с возможностью поиска (например, со сотнями вариантов)?
cokestroke
(Clement Oke)
18.Октябрь.2023 16:19:31
12
Есть ли идеи, как добавить класс к полю, на которое я ориентируюсь? Если нет, можно ли заменить класс QueryySelector на id div?