1

I want to split this line because its too long.

ticketText = `*Environment:*\n${values["environment"]}\n\n*Observed on:*\n${values["observedOn"]}\n\n*Description:*\n${values["description"]}\n\n*Steps:*\n${steps}\n\n*Attachments:*`

I tried this but its adding space at the beginning of Observed on and Steps.

ticketText = `*Environment:*\n${values["environment"]}\n\n
*Observed on:*\n${values["observedOn"]}\n\n*Description:*\n${values["description"]}\n\n
*Steps:*\n${steps}\n\n*Attachments:*`
Fran
  • 193
  • 1
  • 1
  • 9

3 Answers3

1

You can go with this approach:

const values = {
  environment: "UAT",
  observedOn: "Something",
  description: "Something"
};
const steps = "Something";
const ticketText =
  `*Environment:*\n${values["environment"]}\n\n` +
  `*Observed on:*\n${values["observedOn"]}\n\n` +
  `*Description:*\n${values["description"]}\n\n` +
  `*Steps:*\n${steps}\n\n*Attachments:*`;

console.log(ticketText);
Max
  • 1,996
  • 1
  • 10
  • 16
1

You can use a line continuation (\)

const values = { "observedOn":"Friday", "description":"Bla", "environment":"cold" }
const steps = 4;
ticketText = `*Environment:*\n${values["environment"]}\n\n\
*Observed on:*\n${values["observedOn"]}\n\n*Description:*\n${values["description"]}\n\n\
*Steps:*\n${steps}\n\n*Attachments:*`

console.log(ticketText)

Using clipboard

const values = {
  "observedOn": "Friday",
  "description": "Bla",
  "environment": "cold"
};
const steps = 4;
const ticketText = `*Environment:*\n${values["environment"]}\n\n\
*Observed on:*\n${values["observedOn"]}\n\n*Description:*\n${values["description"]}\n\n\
*Steps:*\n${steps}\n\n*Attachments:*`
document.getElementById("btn").addEventListener("click", function() {
  navigator.clipboard.writeText(ticketText).then(function() {
    console.log('Async: Copying to clipboard was successful!');
    navigator.clipboard.readText().then(function(data) {
      document.getElementById("ta").value = data;
    });
  }, function(err) {
    console.error('Async: Could not copy text: ', err);
  });
});
<button id="btn" type="button">Paste from Clipboard</button><br/>
<textarea id="ta" rows=15 cols=50></textarea>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • I tried that before but doesnt work good, its adding a space before Observed on and Steps. I have a button that copy that text to the clipboard and when I paste it I see those whitespaces – Fran Jan 19 '20 at 19:07
  • n o t w o r k i n g – Fran Jan 20 '20 at 18:54
  • @Fran W o r k s f o r m e - see update - you need to allow clipboard access – mplungjan Jan 20 '20 at 22:15
0

You can add \ character to the end of each line:

var values = {
  environment: 'environment',
  observedOn: 'observedOn',
  description: 'description'
};

var steps = 'steps';


console.log(`*Environment:*\n${values["environment"]}\n\n\
*Observed on:*\n${values["observedOn"]}\n\n*Description:*\n${values["description"]}\n\n\
*Steps:*\n${steps}\n\n*Attachments:*`)
Tân
  • 1
  • 15
  • 56
  • 102