0

I tried running this code in the LWC playground and it runs fine for me

When I try to run the same code inside a method in LWC component in salesforce (JavaScript), it's throwing an error.

import {
  LightningElement
} from 'lwc';

export default class InputText extends LightningElement {

  handleCommit(event) {
    var value = event.target.value
    console.log("Value: " + value);

    let validationRule = 'A.length > 5';
    console.log("Validation Rule: " + validationRule);

    let n = validationRule.replace('A', 'value');
    console.log("N: " + n);

    let x = eval(n);
    console.log("X: " + x);

  }
}
<lightning-input type="text" label="Enter some text" oncommit={handleCommit}></lightning-input>

ERROR:

LWC Javascript Error

7
  • Please edit and add the error (after searching for the error first, perhaps it has already been answered) Commented Feb 2, 2024 at 6:46
  • Please check the image for reference. Commented Feb 2, 2024 at 6:58
  • And the console logs show "Value: textFromInput"? What does console.log("N: " + n); show in the two environments? Commented Feb 2, 2024 at 7:04
  • console.log("N: " +n); shows value.length > 5 for both the environment Commented Feb 2, 2024 at 7:06
  • console.log("Value: " +value); shows the value entered in the field. Commented Feb 2, 2024 at 7:07

0

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.