Add placeholder/hint text into custom field using JavaScript not working

Martinlow June 12, 2022

I went to find certain community questions about add placeholder text or hint text into custom field, and found that the answer is to use JavaScript like:

<script type="text/javascript">
document.getElementsByName('customfield_10700')[0].placeholder='This will appear as a placeholder';
</script>

place into custom field's description, but it didn't work at all like below:

Capture.PNG

It displayed at below the field instead of display inside the field.

Any suggest solutions to add placeholder/hint text into field?

1 answer

1 accepted

0 votes
Answer accepted
Florian PEREZ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2022

Hello, 

The method you suggest is not available on cloud, only on server and DC. 

If you want to achieve this you'll have to use context for this specific field and add a default value. While this is not perfect because it fill the field with a real value you don't want to keep you can also try thid other way:

Adding the 'hint' into the description of the custom field, by adding the as a specific field configuration.

Alternatively (but less clean) you can add this information into abother field (the show only field).

Hope this help! 

Martinlow June 12, 2022

Hi,

I noticed that the different between cloud and Server/DC, as I checked from my site, is it considered as Server/DC?

Capture.PNG

Sorry if I choose wrong hosting type.

Thanks.

Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2022

That seems like DC.

 

Do you have 'Enable HTML in field descriptions and list item values' enabled in General configuration (/secure/admin/ViewApplicationProperties.jspa)?

Martinlow June 13, 2022

Nope, it was disabled, should I need to enable it?

Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2022

That depends on your team and if your (global) Jira administrators can be trusted, since at the end of the day, running any javascript with authenticated users could be a serious problem.

I mean I suppose we're talking XSS scripting effectively (https://owasp.org/www-community/attacks/xss/).

In general I would say enabling this is fine, but you should probably decide that on your own.

Martinlow June 13, 2022

I see, what if the field is user picker field, is it able to display placeholder text into it?

I try to enable 'Enable HTML in field descriptions and list item values' and the normal text field able to show the placeholder/hint text in the field, but unable to show for user picker field.

Florian PEREZ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2022

It could be a limitation, but TBH you should try to avoid adding text into a field not supposed to manage text. 

hope this helps

Martinlow June 14, 2022

Thanks for all your responses and answers.

I had a discussion with our team and we decided not to enable the 'Enable HTML in field descriptions and list item values' as will impact other application.

So we will put the hint text below the field instead of inside the field as placeholder.

Once again thanks for the discussion and I'll accept this as answer.

Suggest an answer

Log in or Sign up to answer