2

I want to customize my Jira and need to set a text input field to readonly in javascript / html. I got the following code already, which sets a default value into my customfield "summary":

   window.ATL_JQ_PAGE_PROPS =  $.extend(window.ATL_JQ_PAGE_PROPS, {

          triggerFunction: function(showCollectorDialog) {
            $('#feedback-button').on( 'click', function(e) {
                e.preventDefault();
                showCollectorDialog();
            });
        },

        fieldValues: {
            summary : 'Solution'
                }

          });

</script>

Next step would be to also set the "summary" to readonly, so users can't modify my predefined title anymore. I already tried "document.getElementById("summary").setAttribute("readonly", true);" and similar stuff but it didn't work out. Mayb I did something wrong since I'm not a programmer and someone has an advice?

Thanks in advance

Schmiddi
  • 31
  • 1
  • 4
  • 1
    Does this answer your question? [What is the correct readonly attribute syntax for input text elements?](https://stackoverflow.com/questions/16109358/what-is-the-correct-readonly-attribute-syntax-for-input-text-elements) – goto Apr 17 '20 at 10:59
  • Thanks for fast reply, but I already tried some of these versions and it didn't work out. Maybe I put it in the wrong place and the code itself works. Can you tell me where I have to put some of these ? – Schmiddi Apr 17 '20 at 11:07
  • If you have access to the `HTML` code then edit your answer and show what you've attempted and didn't work - I'll be able to help you better. – goto Apr 17 '20 at 11:34
  • I basically used the above quote and copied it into my script before the tag. I have no idea where to put this. The code I posted initially is all I got till now. What do you mean with access HTML? Should I make a new block under and put it in there? But then it won't relate to the stuff in block or am I wrong? – Schmiddi Apr 17 '20 at 12:35
  • No, that code wouldn't go between your `` tag - `JavaScript` code goes between those tag, `` code between your `` tag. – goto Apr 17 '20 at 12:38
  • Ok now I figured out I have to use some Javascript, like I did to enter that predefined value for my "summary" field. HTML seems not to be working here. I found this in Stackoverflow: ```function onLoadBody() { document.getElementById('control_EMAIL').readOnly = true; }``` But it still doen't work. You have any idea? – Schmiddi Apr 17 '20 at 13:04
  • Does this answer your question? [How to make a input field readonly with JavaScript?](https://stackoverflow.com/questions/17825537/how-to-make-a-input-field-readonly-with-javascript) – Heretic Monkey Apr 17 '20 at 13:41
  • @Schmiddi what do you see when you `console.log(document.getElementById('control_EMAIL'))` prior to doing `ocument.getElementById('control_EMAIL').readOnly = true`? – goto Apr 17 '20 at 23:30
  • Hi, sorry was in holidays for the last week. When I use console.log in this section of Jira simply nothing happens. even when I change logging levels and stuff. – Schmiddi Apr 24 '20 at 12:43

1 Answers1

0

  <input type="text"  value="static value" readonly>

you can do this with read only property it prevent the all type of changing

arslan
  • 1,064
  • 10
  • 19
  • 1
    Thanks for your reply, it turned out I need to use Javascript in my code to get that readonly feature since I can't edit HTML there as I expected. So I'm at the very beginning again. – Schmiddi Apr 17 '20 at 13:13
  • @Schmiddi then you should try this one; document.getElementById("myText").readOnly = true; – arslan Apr 17 '20 at 13:53
  • Sorry for my late answer, but this doesn't work either. Dunno why or what I'll be missing but seems like I cannot access this field. Question is, why I can set a default value in there. – Schmiddi Apr 24 '20 at 12:49
  • for default value just pass variable to value like value={data.value} – arslan Apr 24 '20 at 13:38