1

I am using lightning-record-edit-form to display to users custom Opportunity form with the help of lightning-input-field. However, I am unable to set focus on a particular field.

I have a in a modal window, and I want to focus on this field when the modal opens so that the user doesn't have to use their mouse or tab to set focus.

However, when I try to set focus on Amount field using the below code, it didn't work.

  let fieldToFocus = this.template.querySelector("lightning-input-field[data-fieldname='Amount']");
    if(fieldToFocus){
        fieldToFocus.focus();
    }

Has anybody been able to make focus work with lightning-input-field?

1

Unfortunately lightning-input-field doesn't have @api method focus. You can use lightning-input instead.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.