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 curtidas
Steven
Março 22, 2018, 1:26pm
2
It should already work with this class : div.public-user-field.nameofthefield
For example a custom field Book : div.public-user-field.book
1 curtida
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') {
2 curtidas
tshenry
(Taylor)
Março 22, 2018, 8:05pm
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>
6 curtidas
I will give this a try today, thank you very much
2 curtidas
cokestroke
(Clement Oke)
Agosto 18, 2023, 5:25pm
9
Existe algum plugin que preciso instalar para que isso funcione? Adicionei-o ao cabeçalho do meu tema, mas não parece funcionar para mim.
Canapin
(Coin-coin le Canapin)
Agosto 21, 2023, 12:43pm
10
O código atualizado para a página de perfil é:
<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'; // Usando entrada de data nativa HTML5
}
}
}
});
</script>
Substitua user-field-test-selector pelo nome da classe correspondente:
input.classList.add('testSelector'); é opcional e deve ser adicionado apenas se você precisar dele para modificações futuras, eu acho.
Outro script deve ser feito para o modal de criação de conta.
1 curtida
nathank
(Nathan Kershaw)
Agosto 29, 2023, 11:04pm
11
Isso poderia ser limitado apenas ao ano? Estamos ansiosos para saber a idade aproximada de nossos usuários para monitoramento e gerenciamento de diversidade, mas não queremos reter a data de nascimento completa deles.
Além disso, é possível usar esse tipo de método para ter um campo de lista suspensa pesquisável (ou seja, com centenas de opções)?
1 curtida
cokestroke
(Clement Oke)
Outubro 18, 2023, 4:19pm
12
Alguma ideia de como posso anexar uma classe ao campo que estou a ter como alvo? Falhando nisso, é possível substituir a classe QueryySelector por um ID de div?