3

I am trying to have the data-max value display dynamically inside of the err.push() string to show how many files that e allows.

How do I get the data-max variable to dynamically appear in the error message string?

  let maxFileNum = e.target.getAttribute('data-max'); //Maximum number of files
  if (fileList.files.length > maxFileNum) {
    let tmpf = [];
    err.push('Limit of ${maxFileNum} images allowed');
    fileList.files = tmpf;
  }

1 Answer 1

3

You will have to use back ticks (``) to represent a string literal:

  let maxFileNum = e.target.getAttribute('data-max'); //Maximum number of files
  if (fileList.files.length > maxFileNum) {
    let tmpf = [];
    err.push(`Limit of ${maxFileNum} images allowed`);
    fileList.files = tmpf;
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.